Running into error 1004 trying to copy and paste the cell values over themselves (to eliminate formulas and just get the values). Works fine when I record it on the sheet, alas it doesn't work when I implement it in my subroutine. Error occurs on the PasteSpecial
line:
If i = ws_count Then
'ws_count - 2 allows us to place the new tab before the last sheet in the data file (admin)
Sheets(twomonthsago).Copy Before:=Sheets(ws_count - 2)
Sheets(twomonthsago & " (2)").Name = lastmonth & " test"
Sheets(twomonthsago).Cells.Copy
Sheets(twomonthsago).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
I've also tried directly selecting Range("A1")
before pasting, still getting the error. All my variables have valid strings assigned to them so that isn't the issue.
Assign it directly.
Replace these:
Sheets(twomonthsago).Cells.Copy
Sheets(twomonthsago).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
With:
With Sheets(twomonthsago).UsedRange
.Value = .Value
End With
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.