Finding last column before blank column

aa2000

Board Regular
Joined
Aug 3, 2011
Messages
87
Hi again

So as part of this seemingly never-ending project, there is a section of code which needs to find the last column before a blank column.

So currently I am using some slightly modified code I found on google, but rather than give just the column address it gives the address of the 1st cell in the column

heres the code:
Code:
col = Columns(1).End(xlToRight).Address

So if Column I is blank then col = J1
What should I change so that col just equals J

Thanks
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
This will work up to column Z:-
Code:
col = Chr(64 + Columns(1).End(xlToRight).Column)
Mick
 
Upvote 0
Thanks MickG! This does exactly what I needed.

Out of curiosity what is it that limits it to column Z? And how can I change it to work beyond that?

Cheers
 
Upvote 0
See the "Chr" function in Vb Help".
Chr(64) is "@" which is one before , Chr(65) which is "A" Chr(66) "B" and so on, If you add you Column Number to Chr(64) you will return the column Letter, as per the code.
You could also do this :-
Code:
Col = Split(Columns(1).End(xlToRight).Address, "$")(1)
Mick
 
Last edited:
Upvote 0
Thanks Mick, I looked at the help which meant I could modify it for the other macros.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,216,496
Messages
6,130,983
Members
449,611
Latest member
Bushra

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