#1   Report Post  
BillCPA
 
Posts: n/a
Default 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
  #2   Report Post  
Chip Pearson
 
Posts: n/a
Default

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



  #3   Report Post  
Posted to microsoft.public.excel.misc
HF HF is offline
external usenet poster
 
Posts: 5
Default 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




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 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
  #5   Report Post  
Posted to microsoft.public.excel.misc
HF HF is offline
external usenet poster
 
Posts: 5
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I sort by row instead of by column? PercivalMound Excel Worksheet Functions 7 August 28th 06 10:41 PM
How to group similar column titles together???? vrk1 Excel Discussion (Misc queries) 2 April 30th 05 12:17 AM
Return Count for LAST NonBlank Cell in each Row Sam via OfficeKB.com Excel Worksheet Functions 12 April 17th 05 10:36 PM
up to 7 functions? ALex Excel Worksheet Functions 10 April 12th 05 06:42 PM
How do I reference every "n" cell in a column in Excel? Alma Excel Worksheet Functions 2 March 22nd 05 06:19 PM


All times are GMT +1. The time now is 09:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"