VBA copy and paste method run time error

jeffreybrown

Well-known Member
Joined
Jul 28, 2004
Messages
5,152
I run the procedure below from another procedure, but I get a run time errro.

Run Time error '1004'
Copy method of Range class failed

However, if I run the macro manually by going into the VBE and selecting F5 it runs just fine.

When I step through the procedure x is receiving a numberical value.

Any thoughts? What have I missed?

Code:
Sub UpdateCharts()
    Dim x As Long
    Dim i As Long
    x = Sheets("Sheet1").Range("C2").Value
    With Sheets("Charts")
        For i = 2 To 6
            .Range("Q" & i).Copy Range("Q" & i).Resize(, x)
        Next i
    End With
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi. I think you are missing a dot

Rich (BB code):
Sub UpdateCharts()
    Dim x As Long
    Dim i As Long
    x = Sheets("Sheet1").Range("C2").Value
    With Sheets("Charts")
        For i = 2 To 6
            .Range("Q" & i).Copy .Range("Q" & i).Resize(, x)
        Next i
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,473
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top