我正在使用Excel 2013,我是vba编码的新手,我有几个文件,我必须将数据复制到其中。
所以在给定的时间点,我有源文件(从中复制数据)和目标文件(数据被复制到其中)
两个工作簿打开都会有相同的工作表名称。在下面的vba代码中也创建了一些工作表。我觉得下面的代码效率不高,因为它需要时间来执行和完成它的任务。任何建议都会有很大的帮助
Sub COPYING_GSTv3()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
'Remove password from respective sheets
'---------------------------------------------------
ThisWorkbook.Activate
ActiveWindow.ActivateNext 'toggles the window
Sheets("Budget").Unprotect "bhasad"
Sheets("ET Working").Unprotect "bhasad18"
Sheets("Occupancy").Unprotect "bhasad"
Sheets("Refuel").Unprotect "bhasad"
Sheets("Property Rent").Unprotect "bhasad18"
'---------------------------------------------------
'Replication of "Budget, ET working, Occupancy, Refuel and Property Rent" sheets
'---------------------------------------------------
Sheets("Budget").Range("n63").Copy
Sheets("budget").Range("n65").PasteSpecial xlPasteValues
Sheets("Budget").Range("n1").Formula = "=n63-n65"
Sheets("BUDGET").Copy Before:=Sheets(4)
Sheets("BUDGET (2)").Name = "BUDGET (GST)"
Sheets("ET Working").Copy Before:=Sheets(6)
Sheets("ET Working (2)").Name = "ET Working (GST)"
Sheets("Occupancy").Copy Before:=Sheets(8)
Sheets("Occupancy (2)").Name = "Occupancy (GST)"
Sheets("Property Rent").Copy Before:=Sheets(17)
Sheets("Property Rent (2)").Name = "Property Rent (GST)"
'---------------------------------------------------
'Color sheets
'---------------------------------------------------
With ActiveWorkbook.Sheets("BUDGET (GST)").Tab
.Color = 255
.TintAndShade = 0
End With
With ActiveWorkbook.Sheets("ET Working (GST)").Tab
.Color = 255
.TintAndShade = 0
End With
With ActiveWorkbook.Sheets("Occupancy (GST)").Tab
.Color = 255
.TintAndShade = 0
End With
With ActiveWorkbook.Sheets("Property Rent (GST)").Tab
.Color = 255
.TintAndShade = 0
End With
'---------------------------------------------------
'**pasting data from Budget with GST sheet to repective budget workbook open
'---------------------------------------------------
ThisWorkbook.Activate
Sheets("BUDGET (GST)").Select
Range("A212:m213").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("BUDGET (GST)").Select
Range("A212").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("BUDGET (GST)").Select
Range("b94:m96").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("BUDGET (GST)").Select
Range("b94").Select
ActiveSheet.Paste
Sheets("BUDGET (GST)").Select
Range("b109:m110").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("BUDGET (GST)").Select
Range("b109").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("BUDGET (GST)").Select
Range("b128:m132").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("BUDGET (GST)").Select
Range("b128").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("BUDGET (GST)").Select
Range("b162:m162").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("BUDGET (GST)").Select
Range("b162").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("BUDGET (GST)").Select
Range("b179:m180").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("BUDGET (GST)").Select
Range("b179").Select
ActiveSheet.Paste
'Removing source file name
Cells.Replace What:="[Budget With GST v3.xlsb]", Replacement:="", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("A2:a35").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("A2").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("d9").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("d9").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c16:n17").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c16").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c24:n24").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c24").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c53:n53").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c53").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c69:n69").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c69").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c71:n71").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c71").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c73:n73").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c73").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c78:n78").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c78").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c80:n80").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c80").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c82:n82").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c82").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c88:n88").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c88").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c90:n92").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c90").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c97:n97").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c97").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("ET Working (GST)").Select
Range("c99:n101").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("ET Working (GST)").Select
Range("c99").Select
ActiveSheet.Paste
'Removing source file name
Cells.Replace What:="[Budget With GST v3.xlsb]", Replacement:="", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ThisWorkbook.Activate
Sheets("Occupancy (GST)").Select
Range("d27:p27").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Occupancy (GST)").Select
Range("d27").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Occupancy (GST)").Select
Range("d30:p30").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Occupancy (GST)").Select
Range("d30").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Occupancy (GST)").Select
Range("d32:p32").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Occupancy (GST)").Select
Range("d32").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Occupancy (GST)").Select
Range("d37:p38").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Occupancy (GST)").Select
Range("d37").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Occupancy (GST)").Select
Range("d55:p56").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Occupancy (GST)").Select
Range("d55").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Occupancy (GST)").Select
Range("d63:p63").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Occupancy (GST)").Select
Range("d63").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Occupancy (GST)").Select
Range("d70:p70").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Occupancy (GST)").Select
Range("d70").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Occupancy (GST)").Select
Range("d74:p74").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Occupancy (GST)").Select
Range("d74").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Occupancy (GST)").Select
Range("d76:p76").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Occupancy (GST)").Select
Range("d76").Select
ActiveSheet.Paste
'Removing source file name
Cells.Replace What:="[Budget With GST v3.xlsb]", Replacement:="", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ThisWorkbook.Activate
Sheets("Refuel").Select
Range("e1").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Refuel").Select
Range("e1").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Refuel").Select
Range("a299:m303").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Refuel").Select
Range("a299").Select
ActiveSheet.Paste
'Removing source file name
Cells.Replace What:="[Budget With GST v3.xlsb]", Replacement:="", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ThisWorkbook.Activate
Sheets("Property Rent (GST)").Select
Range("b10:m16").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Property Rent (GST)").Select
Range("b10").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Property Rent (GST)").Select
Range("b26:m31").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Property Rent (GST)").Select
Range("b26").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Property Rent (GST)").Select
Range("b37:m37").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Property Rent (GST)").Select
Range("b37").Select
ActiveSheet.Paste
ThisWorkbook.Activate
Sheets("Property Rent (GST)").Select
Range("b43:m43").Select
Selection.Copy
ActiveWindow.ActivateNext 'toggles the window
Sheets("Property Rent (GST)").Select
Range("b43").Select
ActiveSheet.Paste
'Removing source file name
Cells.Replace What:="[Budget With GST v3.xlsb]", Replacement:="", LookAt _
:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
'---------------------------------------------------
'Differential of Budget and Budget (GST)
Sheets("Budget (GST)").Select
Columns("O:O").Select
Selection.ClearFormats
Range("O10").Select
ActiveCell.FormulaR1C1 = "=RC[-1]-BUDGET!RC[-1]"
Columns("O:O").EntireColumn.AutoFit
Selection.AutoFill Destination:=Range("O10:O201"), Type:=xlFillDefault
Range("O10:O201").Select
Range("O19:O20").Select
Selection.NumberFormat = "0%"
Columns("O:O").ColumnWidth = 7.43
Selection.NumberFormat = "0.0%"
Selection.NumberFormat = "0.00%"
ActiveWindow.SmallScroll Down:=75
Range("O94").Select
Selection.NumberFormat = "0%"
Selection.NumberFormat = "0.0%"
Selection.NumberFormat = "0.00%"
Range("O96").Select
ActiveWindow.SmallScroll Down:=36
Range("O128").Select
Selection.NumberFormat = "0%"
Selection.NumberFormat = "0.0%"
Selection.NumberFormat = "0.00%"
Range("O131").Select
Selection.Style = "Percent"
Selection.NumberFormat = "0.0%"
Selection.NumberFormat = "0.00%"
ActiveWindow.SmallScroll Down:=63
'---------------------------------------------------
'Add password from respective orginal sheets
'---------------------------------------------------
ThisWorkbook.Activate
ActiveWindow.ActivateNext 'toggles the window
Sheets("Budget").Protect "bhasad"
Sheets("ET Working").Protect "bhasad18"
Sheets("Occupancy").Protect "bhasad"
Sheets("Refuel").Protect "bhasad"
Sheets("Property Rent").Protect "bhasad18"
Sheets("Budget").Select
ThisWorkbook.Activate
Sheets("Budget").Select
'---------------------------------------------------
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
End Sub