0
votes

Trying to copy a range from Sheet1 to the same range on 31 sheets but keep getting "Runtime error 1004 : paste method of worksheet class failed" and the debugger indicates ActiveSheet.Paste is the issue. I can copy to a single sheet no problem but not to multiple sheets. I have tried looking everywhere but cannot figure out what the issue is (it's probably something simple too).

Sheets("Sheet1").Range("A1:AR34").Copy
Sheets(Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", _
    "16", "17", "18", "19", "20", "21", "22", "23", "24", "25")).Select
Sheets("1").Activate
Sheets(Array("26", "27", "28", "29", "30", "31")).Select Replace:=False
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
1

1 Answers

0
votes

You can use directly .Copy method without .Select

Sub Bouton1_Clic()
    Dim wsList() As String, wsName As Variant, ws As Worksheet
    Dim wsSource As Worksheet: Set wsSource = ThisWorkbook.Sheets("Sheet1")

    wsList = Split("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31", " ")

    For Each wsName In wsList
        Set ws = ThisWorkbook.Sheets(wsName)
       
        wsSource.Range("A1:AR34").Copy
        ws.Range("A1").PasteSpecial xlPasteValues
        Application.CutCopyMode = xlCopy
    Next wsName

End Sub