I'm trying to write a macro that copies tables (colors, formats etc.) from the sheet for each day (Monday, Tuesday, Wednesday, Thursday and Friday) and pastes to sheets (262 sheets) for the same day. (Monday - Monday etc.) Sheets names I have in sheet "Data".
But I got this error:
Run-time error '1004': Method PasteSpecial class Range Failure.
This is my VBA macro:
Sub copy_paste()
For i = 1 To 262
If 1 = i Mod 5 Then
Worksheets("wednesday").Activate
Cells.Select
Application.CutCopyMode = False
Selection.Copy
' This is the problem part of code (said Debugger)
Sheets(Worksheets("Data").Cells(i, 2).Value).Range("A1").PasteSpecial _
Paste:=x1PasteAllUsingSourceTheme, Operation:=x1None _
, SkipBlanks:=False, Transpose:=False
End If
If 2 = i Mod 5 Then
Sheets("thursday").Select
Application.CutCopyMode = False
Selection.Copy
Sheets(Worksheets("Data").Cells(i, 2).Value).Range("A1").PasteSpecial _
Paste:=x1PasteAllUsingSourceTheme, Operation:=x1None _
, SkipBlanks:=False, Transpose:=False
End If
If 3 = i Mod 5 Then
Sheets("friday").Select
Application.CutCopyMode = False
Selection.Copy
Sheets(Worksheets("Data").Cells(i, 2).Value).Range("A1").PasteSpecial _
Paste:=x1PasteAllUsingSourceTheme, Operation:=x1None _
, SkipBlanks:=False, Transpose:=False
End If
If 4 = i Mod 5 Then
Sheets("monday").Select
Application.CutCopyMode = False
Selection.Copy
Sheets(Worksheets("Data").Cells(i, 2).Value).Range("A1").PasteSpecial _
Paste:=x1PasteAllUsingSourceTheme, Operation:=x1None _
, SkipBlanks:=False, Transpose:=False
End If
If 0 = i Mod 5 Then
Sheets("tuesday").Select
Application.CutCopyMode = False
Selection.Copy
Sheets(Worksheets("Data").Cells(i, 2).Value).Range("A1").PasteSpecial _
Paste:=x1PasteAllUsingSourceTheme, Operation:=x1None _
, SkipBlanks:=False, Transpose:=False
End If
Next i
End Sub
After I fixed these two issues, it works.
You have x1 everywhere in your code instead of xl. – Justyna MK
please check whether it should be Operation:=xlPasteSpecialOperationNone instead of Operation:=x1None – skkakkar