+ Reply to Thread
Results 1 to 4 of 4

Searching a row for a value and returning that column

  1. #1
    Registered User
    Join Date
    05-29-2008
    Location
    Ontario, Canada
    Posts
    19

    Searching a row for a value and returning that column

    Example:

    A B C D E F
    3 4 5 6 7 8

    I need a vba code that will look in the 2nd row for a specific value and return that column's letter. For example, searching the row for 7 would return "E".

    How can I do this?

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Searching a row for a value and returning that column

    Assuming that you have "Headers" in Row 1

    This will return what you want
    Please Login or Register  to view this content.
    where H2 has the value you are looking up

    If you have no header
    Please Login or Register  to view this content.
    where H2 has the value you are looking up


    Hope this helps
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Searching a row for a value and returning that column

    Hi,

    You don't actually need VBA for this you could use standard Excel functions.

    If the result will always be between columns A-Z then:
    Please Login or Register  to view this content.
    otherwise

    Please Login or Register  to view this content.
    it might be advisable to use a variable cell to hold the number 7, or whatever and substitute the cell address for '7' in the formula.

    Rgds
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    05-29-2008
    Location
    Ontario, Canada
    Posts
    19

    Re: Searching a row for a value and returning that column

    Thanks for the responses. The columns do go past Z, all the way to AP. This is part of a much larger macro. Essentially, the user inputs an even integer (ex. 40) and then I need to search for that number in a row. Once I have the row, I need to make a chart with an array of data starting in that column. This is what I have so far:

    Please Login or Register  to view this content.
    First off, the L1 cell that is searching for the formula ends up showing just a 0 instead of a letter.

    It feels like there should be an easier way to do this in the code rather than putting a formula into a cell and extracting that cell's value.

+ 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