Return the last used colum id

Titian

Well-known Member
Joined
Dec 17, 2004
Messages
567
I'm attempting to identify the last populated COLUMN. The following snippet of code returns the number 37, how do I translate 37 into column "AK"?

LC = Cells(9, Columns.Count).End(xlToLeft).Column

Or maybe you have a better way of achieving my requirement.

Thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Can you expand on why you need it converted?

Cells(1, 37).Address returns "AK1"
Range("AK" & 1) is equivalent to Cells(1, 37) - In Range the column letter comes first, then the row number, in Cells, the first argument is the row number, the second is the column number.
 
Last edited:
Upvote 0
Maybe!!!
Code:
Dim Lc As Long, col As String
Lc = Cells(9, Columns.Count).End(xlToLeft).Column
col = Split(Cells(9, Lc).Address(, 0), "$")(0)
MsgBox col
 
Upvote 0
Hi Jack & Mick - thanks for your interest

Jack, I don't know where the last used column is, I'm generating a pivot table from a data set, the width of the PT will vary so I need to know the last column to be able to enter a Ranking formula below the totals generated by the PT

Mick - Great your "col" returns the last column id as required, just one mod please, I want to ignore the Total column of the PT so in effect, get the last column used the return the id of the one to the left of it.

Thanks again
 
Upvote 0
This line of code will assign the letter designation to the variable LC for the farthest right most cell displaying data...
Code:
[table="width: 500"]
[tr]
	[td]LC = Split(Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Address, "$")(1)[/td]
[/tr]
[/table]

Edit Note: I just saw Message #4 . Here is how to get the column to the left of the one calculated above...
Code:
[table="width: 500"]
[tr]
  [td]LC = Split(Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Offset(, -1).Address, "$")(1)[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
For Mick's or Rick's suggestion, just add line:
Rich (BB code):
LC = LC - 1
if you need to return the ID of the one to the left
 
Upvote 0
For ... Rick's suggestion, just add line:
Rich (BB code):
LC = LC - 1
if you need to return the ID of the one to the left
No, my code is returning the column letter designation, not the column number. I have added an Edit Note to my original message with the adjustment for my code line.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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