Last Column

Dathan

New Member
Joined
Oct 25, 2006
Messages
49
I found this code and I am using it to copy a data set of unknown length:

LastRow = Range(col & Rows.Count).End(xlUp).Row

Can someone help me write something similar for a data set of unknown width? I need something that will find the last column. I've tried this:

LastCol = Range(Columns.Count & row).End(xlLeft).Column

or/and

LastCol = Range(Columns.Count & row).End(xlRight).Column

but for some reason it isn't working. Is my problem with this code or is it somewhere else in my macro? Should either of these work? In advance, thanks!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Neither of those will work, Range expects a string representing a range.

I assume here you've defined col as A or whatever?
Code:
LastRow = Range(col & Rows.Count).End(xlUp).Row
To find the last column try this.
Code:
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
Note this will return the column number.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

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