Hi All.
I found the following function on-line. It outputs the Column Number for a given Column Letter.
'Function to calculate column number from column letter
Function ColumnIndex(ColumnLetter As String) As String
Dim singlechar As String
Dim intCode As Integer
Dim loopCounter As Integer
loopCounter = 0
intCode = 0
Do While Len(ColumnLetter) > 0
singlechar = Right(ColumnLetter, 1)
intCode = intCode + (26 ^ loopCounter) * (Asc(singlechar) - 64)
loopCounter = loopCounter + 1
ColumnLetter = Left(ColumnLetter, Len(ColumnLetter) - 1)
Loop
ColumnIndex = intCode
End Function
The user inputs a Column Letter into a userform textbox, 'TBCOL'. From the resulting column number from the function calculation, I wish to refer to this code in the following:
ColNum = Me.TBCOL.Text
ColNumber = ColumnIndex("" & ColNum & "")
MsgBox ColNumber
StartRange = Me.TBSTART.Text
Sheets(SheetName).Select
Set IDRowStart = Columns(??????).Find(what:="" & StartRange & "", After:=Range("B180"))
I have tried the following in the Columns() section:
Columns("& ColNumber &")
Columns(""& ColNumber &"")
Columns("'"& ColNumber &"'")
Columns(& ColNumber &)
Columns & ColNumber
None of the above seem to work. Hopefully the power of the 'Excel Forum' will sort this in a jiffy.
Thanks in advance
Mark
Bookmarks