Get Column Letter of Active Cell in VBA
On Saturday, July 31, 2010 9:31:10 AM UTC-7, MIG wrote:
For some reason, activecell.column returns a number, where as range.select requires a string. So it's not possible to, say, select a range based on returning the current column, or is it? Is there a way of either a) returning the column letter or b) selecting a range based on column number? Thanks. Here ya go MyCol = Columns(ActiveCell.Column).Address this will return a result of $A:$A or whatever column you have active. |
Get Column Letter of Active Cell in VBA
This returns the column label for a specified column index...
Function GetColLabel$(ColNum&) Split(Replace(Columns(ColNum).Address,"$",""),":") (0) End Function This returns the column range address for a specified column index... Function GetColRangeAddr$(ColNum&) Columns(ColNum).Address End Function This returns the column index of the 1st column index of a specified range... Function Get_FirstColNum&(Addr$) Dim sLabel$ sLabel = Split(Split(Addr, ":")(0), "$")(1) GetColNum = Columns(sLabel).Column End Function This returns the column index of the last column index of a specified range... Function Get_LastColNum&(Addr$) Dim sLabel$ sLabel = Split(Split(Addr, ":")(1), "$")(1) GetColNum = Columns(sLabel).Column End Function -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
All times are GMT +1. The time now is 03:52 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com