如何縮短此代碼以重複執行任務,但佔用的空間更少?此代碼需要運行多達27個用戶。我知道我是一個總的小白現在,但是這將減輕我的工作量超過每天一個多小時......用重複/循環縮短VBA代碼
Workbooks.Open ("https://blabla/Edgars/2017 Q3Q4/Edgars.xlsx")
Workbooks("Edgars.xlsx").Activate
Range("C24:AN27").Select
Selection.Copy
Workbooks("abc.xlsx").Activate
Sheets("Edgars").Activate
Range("C24:AN27").Select
ActiveSheet.Paste
Workbooks("Edgars.xlsx").Activate
Sheets("Edgars").Activate
Range("C33:AN36").Select
Selection.Copy
Workbooks("abc.xlsx").Activate
Sheets("Edgars").Activate
Range("C33:AN36").Select
ActiveSheet.Paste
Workbooks("Edgars.xlsx").Activate
Sheets("Edgars").Activate
Range("C42:AN45").Select
Selection.Copy
Workbooks("abc.xlsx").Activate
Sheets("Edgars").Activate
Range("C42:AN45").Select
ActiveSheet.Paste
Workbooks("Edgars.xlsx").Activate
Sheets("Edgars").Select
ActiveWindow.SelectedSheets.Delete
Workbooks("abc.xlsx").Activate
Sheets("Edgars").Select
Sheets("Edgars").Copy Before:=Workbooks("Edgars.xlsx"). _
Sheets(1)
Workbooks("Edgars.xlsx").Activate
Range("A1").Select
ActiveWorkbook.SaveAs Filename:="https://blabla/Edgars/2017 Q3Q4/Edgars.xlsx"
ActiveWorkbook.Close
Workbooks("abc.xlsx").Activate
Worksheets("TOOLS").Activate
Application.DisplayAlerts = True
Else
End If
您應該添加一些信息,簡要描述您的代碼的目的(和/或添加一些註釋)。另外,我不清楚,你的意思是「縮短」。是否有多個文件,需要通過代碼運行?如果是的話,是否有某種命名結構? – Noceo
https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros –
究竟是什麼讓你一小時?運行代碼或調整代碼中的值?使用任何類型的循環很可能不會導致執行速度的顯着變化。 –