Rightmost Column

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there an equivalent to

'LastRow = Cells(Rows.Count, "A").End(xlUp).Row'

for finding the last column to the right that contains data?
 
Use the xlToLeft constant with End. E.g.,

Dim LastCol As Integer
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
Debug.Print LastCol


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Hi Chip,

Do you know if you can use this column count to also get the equivalent
column letter?

For example I get a column count of 54 and that represents column "BB". Is
there a way to convert the column count to the string value?

Thank you.
 
I'm not Chip, but you can use something like:

dim myCol as long
myCol = 54
dim myColLtr
myColLtr = activesheet.cells(1,mycol).address(0,0)
msgbox mycolltr 'you'll see BB1 here
'so strip the last 1 from that string:
msgbox left(mycolltr,len(mycolltr)-1)

But depending on what you're doing, you may not need to know the letter for that
column. If you use Cells(), you can use a string or a number for that column
parm.
 
Thanks Dave. I found a more efficient way of doing what I want that avoids
having to find the column's letter. But I'll keep your code in mind, thanks.
 
Back
Top