+ Reply to Thread
Results 1 to 8 of 8

Get column number by entering a its name

  1. #1
    Registered User
    Join Date
    03-02-2012
    Location
    Toulouse
    MS-Off Ver
    Excel 2007
    Posts
    24

    Question Get column number by entering a its name

    Hi everyone!

    I have an excel file in which the first row containg the names of all the columns (Name, Adress, ZipCode...).

    I need a code to input a name and get the number of the column that has that name. For example, if my first column is "Name", when in the imput box I write "Name" a certain integer, let's say column_num, will get the 1 value.

    Any suggestion? Thank you in advance.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Get column number by entering a its name

    Try MATCH function:

    =MATCH("name", A1:D1, 0)

    For name you can put some reference like Sheet2!A1

  3. #3
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Get column number by entering a its name

    Hi

    You mean to say the row num or the col num?
    Click *, if my suggestion helps you. Have a good day!!

  4. #4
    Registered User
    Join Date
    03-02-2012
    Location
    Toulouse
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Get column number by entering a its name

    My input is the name of the column and my desired output is the number of the column that has the name that I have introduced. Zbor, I'll give your solution a try, thanks!
    Last edited by GerPis; 05-23-2012 at 02:41 AM.

  5. #5
    Registered User
    Join Date
    03-02-2012
    Location
    Toulouse
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Get column number by entering a its name

    That's what I have now:

    Please Login or Register  to view this content.
    I know the line where I use the MATCH function has a bad syntax, but I am a noob with VBA and I don't know how to solve it...

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Get column number by entering a its name

    Try:

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Get column number by entering a its name

    Try this.. I hope this is what you wanted..

    GerPis.xlsm

  8. #8
    Registered User
    Join Date
    03-02-2012
    Location
    Toulouse
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Get column number by entering a its name

    Jraj1106, your solution works but Zbvor's is faster. Thank you both for your ideas, I already could do what I needed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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