+ Reply to Thread
Results 1 to 4 of 4

How to Look-up specific cells in a data table

  1. #1
    Registered User
    Join Date
    09-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    2

    How to Look-up specific cells in a data table

    Hi everyone. I am new to this forum so hopefully have got this post correct!

    I have created a spread sheet that imports a CSV file of data and then I create a number of summary reports from this raw data in other workbook sheets.

    The trouble I have is that the Vlookup and Hlookup functions seem to need a fixed column or row identifier to return a given value. This means the CSV file has to be set-up very precisely with the different columns downloaded from the master database in the same order every time. Unfortunately as I expand this tool and add new data to the CSV file, the order of columns changes and I need to rebuild the whole worksheet.

    Is there a way to use a column heading instead of column number to complete the lookup function. For example lookup cell containing "Mark" from the column heading "Names" and return the result from the column heading "Age". At the moment I can only lookup "Mark" in column 1 and return the value from column 3.

    Similarly I have recorded a macro to sort data automatically, but the macro also only picks columns by number. For example
    Selection.AutoFilter Field:=5, Criteria1:="<>"

    Is there a way that field 5 can be identified by the data title rather than position in the spread sheet? Ie it does not matter if the "Age" column is the 5th or 4th in the CSV file.

    Thanks for your help with this...

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to Look-up specific cells in a data table

    The VLOOKUP only works looking left>right and HLOOKUP only works looking from top>bottom.

    A more versatile approach it INDEX/MATCH. You can INDEX column A, then "match" a value to column B to get the correct row, thus getting an answer back from column A on that same row. That's the opposite of what VLOOKUP typically does.

    =INDEX(Sheet1!A:A, MATCH("Doug", Sheet1!B:B, 0))


    INDEX/MATCH replaces HLOOKUP the same way. If you know you want to get the value in row 2 from the column that has "AGE" in row 1, HLOOKUP can do it, but so can INDEX/MATCH.

    =HLOOKUP("Age", Sheet1!1:2, 2, 0)
    =INDEX(Sheet1!2:2, MATCH("Age", Sheet1!1:1, 0))
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: How to Look-up specific cells in a data table

    That's genius!
    Thanks for the help.

    To take this one step further, it is possible to embed the MATCH function into macro code?
    ie modify the code:
    Selection.AutoFilter Field:=5, Criteria1:="<>"
    such that it does not always filter column 5 but instead does something like
    Field:=variable where variable=the output from a MATCH function calculation?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to Look-up specific cells in a data table

    You would declare a LONG variable, then use a MATCH function to find which column a specific value is in a specific row and store it in that variable, then use the variable for your filter Field.

    So if you were looking for "Age" somewhere in row1:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. I'm having trouble pasting data into specific cells in a table
    By phanjoe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-21-2012, 11:36 PM
  2. Replies: 0
    Last Post: 09-17-2012, 11:10 AM
  3. Macro to copy specific data to specific columns from a pivot table
    By Raju Radhakrishnan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-09-2012, 07:24 PM
  4. VBA Trying to pull specific Word table cells into specific Excel cells
    By ez08mbba in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-16-2012, 01:11 PM
  5. finding specific data from one table and pasting it into another table
    By saranorton in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-29-2011, 09:35 AM

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