Results 1 to 5 of 5

Referring to a Column Number in vba code - Found Via Function using Column Letter

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-28-2008
    Location
    Leamington Spa, UK
    MS-Off Ver
    2010
    Posts
    142

    Question Referring to a Column Number in vba code - Found Via Function using Column Letter

    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
    Last edited by R_S_6; 09-01-2010 at 10:23 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1