+ Reply to Thread
Results 1 to 11 of 11

How to do a Vlookup without knowing the column number

  1. #1
    Registered User
    Join Date
    11-04-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    10

    How to do a Vlookup without knowing the column number

    I have a spreadsheet that I currently use to track the total revenue for a variety of different products. The data is pulled from a Pivot on a different sheet that is updated daily. I currently use VLookup to pull this information by matching the ItemID (Column A).

    Here is my problem: I need to add the monthly revenue for each month after a product is released to this spreadsheet. Unfortunately, each product has a different release date so I can't tell Vlookup an exact column number to search for the corresponding data.

    Is there a way I can do a conditional statement or something similar instead of giving an exact column number in Vlookup? For example, have it look for the first column that contains data and return that as Month 1, and so on for month 2, 3, etc. If not, can you think of any other way to set this up? Also, please note that some months may have 0 revenue, which will need to be included as a value, not skipped over.

    I have attached a sample Workbook that is modeled in a similar way to the actual spreadsheet I am using, except MUCH less data and using a static table for the source data instead of a dynamic Pivot table. Does anyone have any idea how I can populate the month revenue from the 'Source Data' sheet? Please note that the actual spreadsheet I am using has the Pivot table refreshed daily with updated information and there are new products added all the time so the information never stays in the same column or row #.

    P.S. On the 'Source Data' sheet you will notice that the Year and Month headers are on separate rows, unfortunately I can't alter this (DB is read-only) to have them combined on 1 line (e.g. Dec. 2012, Jan. 2013, etc), which means I can't look the column up by matching the Release Date to the corresponding Month & Year.
    Attached Files Attached Files

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: How to do a Vlookup without knowing the column number

    Try this in the Sales Tab E2 and filled right/down

    =INDEX('Source Data'!D$3:D$12,MATCH($A2,'Source Data'!$A$3:$A$12,0))

  3. #3
    Registered User
    Join Date
    11-04-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: How to do a Vlookup without knowing the column number

    No, that returned the values in column D (Dec. 2012) for Month 1. Dec. 2012 shouldn't be Month 1 for all of the items, Month 1 will be different depending on when the item released. Essentially, I need Month 1 revenue to be the first column on each item's row that contains a value.

    For example:

    Item 1: Mo. 1 rev = 342.00
    Item 2: Mo. 1 rev = 260.00
    Item 3: Mo. 1 rev = 322.00
    and so on..

    Does that make sense?

    Quote Originally Posted by Jonmo1 View Post
    Try this in the Sales Tab E2 and filled right/down

    =INDEX('Source Data'!D$3:D$12,MATCH($A2,'Source Data'!$A$3:$A$12,0))

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: How to do a Vlookup without knowing the column number

    funroe,

    Attached is a modified version of your posted sample workbook.
    In sheet 'Sales' cell E2 and copied over and down is this formula:
    Please Login or Register  to view this content.

    Does that work for you?
    Attached Files Attached Files
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: How to do a Vlookup without knowing the column number

    Must be an easier way but this works in E2 copied down and across. It must be entered as an array formula (using CNTRL SHFT ENTER)

    =IFERROR(INDEX('Source Data'!$D$3:$H$12,MATCH($A2,'Source Data'!$A$3:$A$12,0), MATCH(1, 1/(ISNUMBER(INDEX('Source Data'!$D$3:$H$12, MATCH($A2, 'Source Data'!$A$3:$A$12,0),))),0)+COLUMN(A1)-1),"")

    See attachment
    Attached Files Attached Files
    Last edited by ChemistB; 05-09-2013 at 04:46 PM.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: How to do a Vlookup without knowing the column number

    If you change your headings to real dates...1/1/13, 2/1/13 etc, then you can use this, copied down and across...

    =INDEX('Source Data'!$A$2:$I$12,MATCH($A2&$B2&$C2,'Source Data'!$A$2:$A$12&'Source Data'!$B$2:$B$12&'Source Data'!$C$2:$C$12,0),MATCH(E$1,'Source Data'!$A$2:$I$2,0))

    ...confirmed by pressing CTRL-SHIFT-ENTER to activate the array. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL-SHIFT-ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Registered User
    Join Date
    11-04-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: How to do a Vlookup without knowing the column number

    Hi tigeravatar-

    When I attempted to place this in my spreadsheet the formula wouldn't work for all of the cells because I have many years worth of data. For example, the month of January exists multiple times from 2006-2013 so the formula only wants to return the first instance of this value, which is 2006 and it uses Jan. 2006 that for every month of January after that.

    I revised that spreadsheet to include more than one years worth of data and changed the release dates. If you look at the values for Item 1 in Months 11-13, the values don't match the Source Data because the formula appears to be looking for values from 2012 so instead of Month 13 having data from March 2013, it shows data from March 2012. I attached the revised spreadsheet to this thread.

    Is there any way you can think of around this? That's why I didn't try to match the release date month to the column headers, because the way it's set up, the month and year are on separate lines.



    Quote Originally Posted by tigeravatar View Post
    funroe,

    Attached is a modified version of your posted sample workbook.
    In sheet 'Sales' cell E2 and copied over and down is this formula:
    Please Login or Register  to view this content.

    Does that work for you?
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    11-04-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: How to do a Vlookup without knowing the column number

    Hi FDibbins-

    I can't change the column headings in the Source Data as this is from a read-only Database and even if I change it now, when I refresh the query, it will overwrite my changes.

    Quote Originally Posted by FDibbins View Post
    If you change your headings to real dates...1/1/13, 2/1/13 etc, then you can use this, copied down and across...

    =INDEX('Source Data'!$A$2:$I$12,MATCH($A2&$B2&$C2,'Source Data'!$A$2:$A$12&'Source Data'!$B$2:$B$12&'Source Data'!$C$2:$C$12,0),MATCH(E$1,'Source Data'!$A$2:$I$2,0))

    ...confirmed by pressing CTRL-SHIFT-ENTER to activate the array. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL-SHIFT-ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: How to do a Vlookup without knowing the column number

    OK well if teh table/s is/are not that big, can you reference them to some other location andthen use my suggestion there?

    Otherwise, I hope that ChemistB's suggestion will help

  10. #10
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: How to do a Vlookup without knowing the column number

    funroe,

    Attached is a modified version of your posted "v2" workbook.
    In sheet 'Sales' cell E2 and copied over and down is this formula:
    Please Login or Register  to view this content.

    Does that work for you?

  11. #11
    Registered User
    Join Date
    11-04-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: How to do a Vlookup without knowing the column number

    I think that worked!! Thank you so much for your help. I am going to keep messing with this. I have a quick question: what if I wanted to make this cumulative? Is there a way to make it so it adds the value of the previous cell into the current month when calculating it? I'm thinking of eventually creating benchmarks for 1month, 6months, 9months, 12months and 24months.


    Thanks again for all of your help!!



    Quote Originally Posted by ChemistB View Post
    Must be an easier way but this works in E2 copied down and across. It must be entered as an array formula (using CNTRL SHFT ENTER)

    =IFERROR(INDEX('Source Data'!$D$3:$H$12,MATCH($A2,'Source Data'!$A$3:$A$12,0), MATCH(1, 1/(ISNUMBER(INDEX('Source Data'!$D$3:$H$12, MATCH($A2, 'Source Data'!$A$3:$A$12,0),))),0)+COLUMN(A1)-1),"")

    See attachment

+ 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