ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert Column Number to Column Letter (https://www.excelbanter.com/excel-programming/440296-convert-column-number-column-letter.html)

Philosophaie

Convert Column Number to Column Letter
 
I have the last column of data. I want to use a range to say copy or define
something. So how do you convert the number LastCol to a letter to display
in a Range:

LastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column

JLatham

Convert Column Number to Column Letter
 
A web search for "convert column number to letter" turned up several hits,
one of which was:
http://www.mrexcel.com/forum/showthread.php?t=102298
look at the last 3 posts in that discussion. Two ways to get the job done.
Personally, since you've gone the route you have at this point, I'd probably
go with the solution in the last posting. Especially if you've got Excel
2007 where column letter IDs can go to 3 characters, not just 2.

You could do something like:
LastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
fullAddress= Cells(1, LastCol).Address
'returns something like $A$1 or $EF$1 in fullAddress
colID = Left(fullAddress, InStr(2, fullAddress, "$") - 1)
'will give you $A or $EF type returns



"Philosophaie" wrote:

I have the last column of data. I want to use a range to say copy or define
something. So how do you convert the number LastCol to a letter to display
in a Range:

LastCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column



All times are GMT +1. The time now is 04:30 AM.

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