+ Reply to Thread
Results 1 to 5 of 5

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

  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.
    Please Login or Register  to view this content.
    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:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I have tried the following in the Columns() section:
    Please Login or Register  to view this content.
    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.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Refering to a Column Number in vba code - Found Via Function using Column Letter

    In that context:

    Please Login or Register  to view this content.
    would suffice

    FWIW if you need the column number far quicker to use something like:

    Please Login or Register  to view this content.

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

    Question Re: Refering to a Column Number in vba code - Found Via Function using Column Letter

    Thanks for your reply.

    I cant reference the textbox 'TBCOL' as it contains a Letter selected by the user for the column, for instance 'A'. I use the function to get the number of the column, in this case '1' that would then replace:
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    Thus allowing the resulting calculated column number to be a variable dependant upon the user selected column letter.

    Hopefully the above makes things clearer?
    I have tried your top piece of code with no luck - Any ideas?

    Thanks for your help - its very much appreciated!
    mark

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

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

    DO's suggestion should work fine. You can reference columns by letter, e.g.,
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

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

    Thumbs up Re: Referring to a Column Number in vba code - Found Via Function using Column Letter

    A Thousand Apologies! The Function was returning number '3' for column 'C' which is correct. What was incorrect is that I was supposed to be using column B i.e. 2!
    Knowing that now - Both your suggestions are much much simpler and logical!

    Thank you both - Apologies again!
    Mark

+ Reply to Thread

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