ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Rightmost Column (https://www.excelbanter.com/excel-discussion-misc-queries/25733-rightmost-column.html)

BillCPA

Rightmost Column
 
Is there an equivalent to

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

for finding the last column to the right that contains data?

--
Bill @ UAMS

Chip Pearson

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



"BillCPA" <Bill @ UAMS wrote in message
...
Is there an equivalent to

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

for finding the last column to the right that contains data?

--
Bill @ UAMS




HF

Rightmost Column
 
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.

"Chip Pearson" wrote:

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



"BillCPA" <Bill @ UAMS wrote in message
...
Is there an equivalent to

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

for finding the last column to the right that contains data?

--
Bill @ UAMS





Dave Peterson

Rightmost Column
 
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.





HF wrote:

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.

"Chip Pearson" wrote:

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



"BillCPA" <Bill @ UAMS wrote in message
...
Is there an equivalent to

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

for finding the last column to the right that contains data?

--
Bill @ UAMS





--

Dave Peterson

HF

Rightmost Column
 
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.

"Dave Peterson" wrote:

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.





HF wrote:

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.

"Chip Pearson" wrote:

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



"BillCPA" <Bill @ UAMS wrote in message
...
Is there an equivalent to

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

for finding the last column to the right that contains data?

--
Bill @ UAMS




--

Dave Peterson


Dave Peterson

Rightmost Column
 
Change this line:
dim myColLtr
to
dim myColLtr as String



Dave Peterson wrote:

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.

HF wrote:

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.

"Chip Pearson" wrote:

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



"BillCPA" <Bill @ UAMS wrote in message
...
Is there an equivalent to

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

for finding the last column to the right that contains data?

--
Bill @ UAMS




--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 11:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com