我有以下代码
Sub WorksheetCopy()
' Dimensions variables as workbooks
Dim WbSource As Workbook
Dim WbDest As Workbook
Dim CopyYear As Integer
Dim YearCount As Integer
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim YearDate As String
Application.ScreenUpdating = False ' Turns off notifications
Set WbSource = ThisWorkbook ' Sets this workbook as the Source Workbook
Set WbDest = Workbooks.Open("C:\Users\U486474\Desktop\Lv 2 Templates\HoursLog.xlsx") ' Sets the Destination workbook
' hard coded to a specific file location
CopyYear = 2015 ' Sets first year to copy data minus 1 year for counter
For YearCount = 1 To 3 ' Loop to define number of years report is to copy ' Currently the loop runs 3 times for 2016, 2017 and 2018
CopyYear = CopyYear + 1 ' increments per year
YearDate = CopyYear ' converts variable to a string to be use in named fields
Debug.Print " CopyYear " & CopyYear & " YearCount " & YearCount & " YearDate " & YearDate ' just for testing
Set WS1 = WbSource.Sheets(YearDate) ' Sets the Source Workbook / Worksheet and the year to be copied from
Set WS2 = WbDest.Sheets(YearDate) ' Sets Destination Workbook / Worksheet and the year to be pasted to
WS1.Cells.Copy WS2.Cells ' command to copy from the source worksheet and paste into the destination worksheet
Next
WbDest.Close True 'Saves and Closes destination workbook
Application.ScreenUpdating = True ' Turns Notifications back on
End Sub
当发生复制命令时,会打开更新值窗口。这会停止例行程序,直到您取消选择窗口。 除此之外,例程工作正常。 我正在尝试自动执行此例程,并且不希望任何用户输入。
其次我一直在努力解决的问题是如何粘贴为值。 细胞含有配方。我只需要报告的值。 从搜索论坛
WS1.Range("A1:CZ14400").Copy
WS2.Range("A1:CZ14400").PasteSpecial xlPasteFormulas
代替复制命令行
它没有用,我得到了一个内存不足的错误 文件很大.. 32 meg
请帮助。
谢谢