VBA copy to another sheet not working

Edjas

New Member
Joined
Dec 7, 2016
Messages
5
Hi there,

Im pretty new to this and i can't figure someting out. I have the next piece of code:
Private Sub CheckBox1_Click()

i = Worksheets("Checklist").Cells(10, 15)
If CheckBox1 = True And i > 0 And i < 13 Then
Worksheets("Tabellen").range(Cells(45, 1), Cells(47 + i, 7)).Copy Worksheets("Tabellen").range(Cells(45, 10), Cells(47 + i, 16))
End If

End Sub

This code works fine, but if i change the worksheet after the copy to "Checklist":

(Worksheets("Tabellen").range(Cells(45, 1), Cells(47 + i, 7)).Copy Worksheets("Checklist").range(Cells(45, 10), Cells(47 + i, 16))
I get error code 1004
Other copy codes works fine if I want to copy to another worksheet, for example:

If CheckBox8 = True Then
Worksheets("Tabellen").range("E75:H87").Copy Worksheets("P8").range("E27:H39")
Else
Worksheets("P8").range("E27:H39").Clear
End If

but I can't figure out why the first one doesn't work.

I hope someone can help me with this.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You need worksheet references for every instance of Cells in the code.

Mind you for the destination you can use the top-left cell rather than specifying the whole range.

Try this.
Code:
With Worksheets("Tabellen")
    .Range(.Cells(45, 1), .Cells(47 + i, 7)).Copy Worksheets("Checklist").Cells(45, 10)
End With

PS You might also want to look at using Resize, for example this,
Code:
.Range(.Cells(45, 1), .Cells(47 + i, 7))
can be written as this.
Code:
Cells(45, 1).Resize(3 + i, 7)
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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