D
dhstein
Below is a function that will return the column of a cell. The "CELL"
function will give a column number - I want the column name e.g. "AM". The
function works - sort of. The problem is if I have a cell with "=COL()" I
can't copy that formula to other cells. I think I'm using the wrong Address
(Selection.Address). Any advice is appreciated. Thanks.
Function Col(Optional Column As Integer)
' This Function is used to return the column of a cell - useful for
"INDIRECT" function
' Typical use is =col(CELL("COL",AM1)) - this would return the value "AM"
' Alternatively can be called as =col() which returns the column of the
current cell
Select Case Column
Case Is > 0
FC = Chr(Int((Column - 1) / 26) + 64)
SC = Chr(((Column - 1) Mod 26) + 65)
If Column < 27 Then
Col = SC
Else
Col = FC + SC
End If
Case Is = 0
Addr = Selection.Address
First_Dollar = Application.WorksheetFunction.Find("$", Addr, 1)
Second_Dollar = Application.WorksheetFunction.Find("$", Addr,
First_Dollar + 1)
Col = Mid$(Addr, 2, (Second_Dollar - First_Dollar) - 1)
End Select
End Function
function will give a column number - I want the column name e.g. "AM". The
function works - sort of. The problem is if I have a cell with "=COL()" I
can't copy that formula to other cells. I think I'm using the wrong Address
(Selection.Address). Any advice is appreciated. Thanks.
Function Col(Optional Column As Integer)
' This Function is used to return the column of a cell - useful for
"INDIRECT" function
' Typical use is =col(CELL("COL",AM1)) - this would return the value "AM"
' Alternatively can be called as =col() which returns the column of the
current cell
Select Case Column
Case Is > 0
FC = Chr(Int((Column - 1) / 26) + 64)
SC = Chr(((Column - 1) Mod 26) + 65)
If Column < 27 Then
Col = SC
Else
Col = FC + SC
End If
Case Is = 0
Addr = Selection.Address
First_Dollar = Application.WorksheetFunction.Find("$", Addr, 1)
Second_Dollar = Application.WorksheetFunction.Find("$", Addr,
First_Dollar + 1)
Col = Mid$(Addr, 2, (Second_Dollar - First_Dollar) - 1)
End Select
End Function