+ Reply to Thread
Results 1 to 16 of 16

Automating VLookups

  1. #1
    Registered User
    Join Date
    05-28-2015
    Location
    Lakeland, FL
    MS-Off Ver
    Excel 13
    Posts
    66

    Automating VLookups

    I have about 300 sheets in one workbook. The first sheet is named "Cumulative Data" and for each row I would like to pull specific data from one worksheet. The second sheet is named "soldList" and in Column J has a list of all the names for the other 200 worksheets. Each one of the worksheets has different data in it and each data is not in the same location from one worksheet to the next. For example, the buyer's name in worksheet 1 could be in row 30 and in worksheet 2 it is in 15. Is there way to make a macro to do a vlookup for the same information on each sheet and put in the cumulative data in the same column. For example, if I want to get all the Buyer's name from all the worksheets and put it in column B in "Cumulative Data" worksheet.

  2. #2
    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,929

    Re: Automating VLookups

    Probably dont need VBA for this, INDIRECT will probably do what you want, seeing as you have a list of the sheet names

    upload a small (clean) sample workbook (not a pic) of what you are working with, and what your expected outcome would look like.
    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

  3. #3
    Registered User
    Join Date
    05-28-2015
    Location
    Lakeland, FL
    MS-Off Ver
    Excel 13
    Posts
    66

    Re: Automating VLookups

    I have attached an example file, with what I need. The red column is where I want the Buyer's name from each sheet to be in. Also if I wanted Seller's Name, Buyer's Name, Date listed, Date sold and other columns filled the same way would I have to do it for each column individually?
    Attached Files Attached Files

  4. #4
    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,929

    Re: Automating VLookups

    I presume your sheet names are not as simple as 1, 2, 3 etc?

  5. #5
    Registered User
    Join Date
    05-28-2015
    Location
    Lakeland, FL
    MS-Off Ver
    Excel 13
    Posts
    66

    Re: Automating VLookups

    Correct, the sheet names are nine numbers long and are in no order at all.

  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,929

    Re: Automating VLookups

    OK, try this, copied down...
    =IFERROR(INDEX(INDIRECT("'"&soldList!$J2&"'!$B$1:$B$100"),MATCH(L$1,INDIRECT("'"&soldList!$J2&"'!$A$1:$A$100"),0)),"")

  7. #7
    Registered User
    Join Date
    05-28-2015
    Location
    Lakeland, FL
    MS-Off Ver
    Excel 13
    Posts
    66

    Re: Automating VLookups

    I copy and pasted it into the cell and it just gives me a blank cell.

  8. #8
    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,929

    Re: Automating VLookups

    It should have given an error message I forgot to tell you to add a : to the end of L1 "Buyer Name", so it matches the data on the sheets.

    Did you put that in *** Data L2, copied down?

  9. #9
    Registered User
    Join Date
    05-28-2015
    Location
    Lakeland, FL
    MS-Off Ver
    Excel 13
    Posts
    66

    Re: Automating VLookups

    After I put a ":" at the end of Buyer Name it worked! Thank you so much!

  10. #10
    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,929

    Re: Automating VLookups

    LOL the forum server replaced the abbreviation for Cumulative, with ***

    ANyway, Im happy that worked for you. If this answered your question, please take a moment to mark the thread as "solved" - it helps keep things neat and tidy lol, and consider adding the reputation to those that helped (see points 2 & 3 below my 1st post to you)

  11. #11
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Automating VLookups

    Nuccio92,

    If you must cross-post, please provide a link to the other forum as I have done with with this link. Failure to do so is in breach of Rule 8 (refer here) of our forum rule Don't cross-post without a link.

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  12. #12
    Registered User
    Join Date
    05-28-2015
    Location
    Lakeland, FL
    MS-Off Ver
    Excel 13
    Posts
    66

    Re: Automating VLookups

    Thank you! Could you kind of explain what the formula says so if I ever have to do something similar I would be able to figure it out on my own?

  13. #13
    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,929

    Re: Automating VLookups

    =IFERROR(INDEX(INDIRECT("'"&soldList!$J2&"'!$B$1:$B$100"),MATCH(L$1,INDIRECT("'"&soldList!$J2&"'!$A$1:$A$100"),0)),"")

    It is a *basic* INDEX/MATCH, really, but I added INDIRECT() to cater for the sheet names being variable.

    If you are not familiar with INDEX/MATCH, let me know and I will explain that part.

    Excel cannot normally use text as a reference in a formula (apart from range names), so we use INDIRECT to convert that text into something excel can use. I have used this twice in the formula, just changed the range it applies to. Both work the same, so I will explain the 1st 1

    1. =INDIRECT("'"&soldList!$J2&"'!$B$1:$B$100")
    excel adds ' at the start and end of a sheet name, so thats what we need to put in there 1st, but ' on its own is text, so you will see that I wrapped it in "" (as for all text, used in any formula)

    2. =INDIRECT("'"&soldList!$J2&"'!$B$1:$B$100")
    You join (concatenate) things in excel by using &, si I am using that to combine ' with the sheet name
    I get the sheet name from the SoldList sheet, in column J2, downwards - in this case, SoldList!J2 contains 1 (sheet name 1)

    3. =INDIRECT("'"&soldList!$J2&"'!$B$1:$B$100")
    The last part is the range that is being used. This is what you would need to adjust is your range is longer than 100 lines on each of your sheets. If you have some sheets longer than others, you dont need to adjust it for each sheet, just make it cater for the longest sheet.
    Again, it starts with & to show we want to combine something. Then the " for text and then '! (to finish off the sheet name), followed by the range

    Hope that made sense? If not, shout again

    (thanks for the feedback, too)

  14. #14
    Registered User
    Join Date
    05-28-2015
    Location
    Lakeland, FL
    MS-Off Ver
    Excel 13
    Posts
    66

    Re: Automating VLookups

    That is extremely helpful and actually makes sense to me! And I am not too familiar with INDEX/MATCH and why it is =IFERROR instead of vlookup? I hate to keep bothering you, but I do greatly appreciate the help!

  15. #15
    Registered User
    Join Date
    05-28-2015
    Location
    Lakeland, FL
    MS-Off Ver
    Excel 13
    Posts
    66

    Re: Automating VLookups

    Quote Originally Posted by Trebor76 View Post
    Nuccio92,

    If you must cross-post, please provide a link to the other forum as I have done with with this link. Failure to do so is in breach of Rule 8 (refer here) of our forum rule Don't cross-post without a link.

    Robert
    My apologies! Didn't know about that, won't happen again!

  16. #16
    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,929

    Re: Automating VLookups

    The IFERROR() is there to catch/trap error answers. If the MATCH in INDEX/MATCH (explained below) does not find a match, it gives an error message. IFERROR replaces that message what something of your choosing. The syntax is...
    =IFERROR(formula,what-to-show-if-error-is-found)
    So, if your formula works OK, its result is shown, otherwise whatever you put in the "what-to=show" part, is displayed. This could be nothing "" (like I used), it could be a message "no data found", or it could even be another formula.

    INDEX returns a value at the intersect (meeting) of a row and a column.
    =INDEX(range,row-num,column-num)
    MATCH finds a specified criteria in a column or row.
    =MATCH(Criteria-to-find,column-(or row)-to-search,0) The 0 returns an exact match

    So when you put them together, you have a very powerful tool for returning a value from an unknown intersection of rows and columns.
    INDEX/MATCH (or INDEX/MATCH/MATCH if you need to return data from different columns), lets you determine that intersect (meeting).

    To keep this simple, I will use the same formula, but base it off ONLY sheet 1 (the INDIRECT() bit just muddles up the explanation, and we have already been through that)

    =INDEX('1'!$B$1:$B$30,MATCH("Buyer Name:",'1'!$A$1:$A$30,0))
    This is what that formula would look like in it's simplest form

    I then used a cell reference, so that the hard-coded name can change...
    =INDEX('1'!$B$1:$B$30,MATCH(L$1,'1'!$A$1:$A$30,0))

    What this is doing, is saying (you generally read formulas from the inside, outwards)...
    Find "Buyer Name:" in sheet 1, in range A1:A30, and find an exact match (the $ is there to "fix" the range so it doesnt adjust when copied)
    OR
    Find the contents of L1 in sheet 1, in range A1:A30, and find an exact match
    This returns row 12, in this case

    This will give you a row number. INDEX uses that to return a value. (we did not use the 2nd MATCH because we already know the column that contains out info - A)
    So INDEX will go down its range, and look for the contents in the 12th row

    To see how all this is working, click on the formula, then click on the Fx button to the left of the formula bar, it will also help you understand what different parts of the formula is doing, and will help you lear/underatand
    =IFERROR(INDEX(INDIRECT("'"&soldList!$J2&"'!$B$1:$B$100"),MATCH(L$1,INDIRECT("'"&soldList!$J2&"'!$A$1:$A$100"),0)),"")

+ 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. Replies: 2
    Last Post: 07-14-2013, 03:13 PM
  2. Excel 2007 : vlookups
    By Cerena in forum Excel General
    Replies: 17
    Last Post: 05-29-2012, 01:02 AM
  3. Why use VLOOKUPs
    By adamwestrop in forum Excel General
    Replies: 1
    Last Post: 08-13-2011, 09:55 AM
  4. SUM VLOOKUPs
    By djones13 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-27-2011, 02:50 PM
  5. vlookups
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2005, 11:06 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