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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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