VBA copy row to column

raaone

New Member
Joined
Oct 21, 2017
Messages
4
Hi all, newbie here.
I'm trying to copy a row of cells from one sheet (Sheet1) to the first empty cell in column 2 on another sheet (Sheet2) using a checkbox.
Here is my code:
If CheckBox2.Value = True Then
Dim xCell As Range
Worksheets("Sheet1").Range("A9:K9").Copy
' On Error Resume Next
For Each xCell In Sheets("Sheet2").Columns(2).Cells
If Len(xCell) = 0 Then
Worksheets("Sheet2").Range(xCell).PasteSpecial Transpose:=True
Exit For
End If
Next
End If

The error message I get at line beginning with Worksheets("Sheet2"). is
"Application-defined or object-defined error"

Could someone give me a hint as to what I'm doing wrong.
Many thanks.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi & welcome.
Try this
Code:
Worksheets("Sheet1").Range("A9:K9").Copy
Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Transpose:=True
 
Upvote 0
Hi & welcome.
Try this
Code:
Worksheets("Sheet1").Range("A9:K9").Copy
Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Transpose:=True

Worked beautifully. Thank you.
Would you be kind enough to give me a brief explanation of "End(xlUp)" 

Thanks again.
 
Upvote 0
.End(xlUp) Moves up from the startpoint (in this case B1048576, on newer versions of xl) until it finds a cell that is not blank.
It is the same as going to the very last row of the sheet & doing Ctrl+uparrow
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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