Copy ranged cells fails

rlekkala

New Member
Joined
Feb 3, 2009
Messages
49
The following code works fine for EntireRow.Copy
But I want to copy only the cells that have values in them (copying entire row is screwing up the auto expandable table in the other sheet)

Error says "Method range of obect workseet failed"
Sub exa()
Dim row As Long
Dim col As Long

With Sheet1 'or ThisWorkbook.Worksheets("Sheet1")
row = .Range("A" & Rows.Count).End(xlUp).row
col = .Range("1" & Columns.Count).End(xlToLeft).Column

If Not row > 1 Then Exit Sub

.Range("A2:A" & row).SpecialCells(xlCellTypeVisible).Range("1:1" & col).Copy _
ThisWorkbook.Worksheets("Sheet2").Cells(2, 1)
End With
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I don't know what you are trying to do here but this part can't be right:

.Range("1:1" & col).Copy _

You're telling it to to the whole row 1.. or column... and then a column.
 
Upvote 0
I don't know what you are trying to do here but this part can't be right:

.Range("1:1" & col).Copy _

You're telling it to to the whole row 1.. or column... and then a column.

When I use EntireRow.Copy it copies the entire row, but I want only the columns until the last column with values in the first row or lets say second row (since our range starts with row 2)

I want to copy all rows that have values only for the columns that have values (not entire row)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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