+ Reply to Thread
Results 1 to 4 of 4

Trouble with code containing nested vlookup

  1. #1
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2013
    Posts
    142

    Trouble with code containing nested vlookup

    Hello All,

    I've been hunting and pecking the message board to try to develop some VBA code that will work for me. But, since I only know VBA well enough to be dangerous I'm running into problems. What I have so far is:

    Please Login or Register  to view this content.
    What I'm basically trying to accomplish is to have the formula copied in column I, beginning at I2 and ending at the last row where there is data. The error I'm getting is "Compile error: Expected End of Statement" and it highlights the first instance of the word Core in the formula line.

    The formula is supposed to lookup the value in column F in the table I have named Workshop and return the value in the second column of that table. If it returns "Core/Subcore", it shows that value. If it does not return "Core/Subcore" then it looks up the value in column G in the table I have named Module and returns the value in the second column of that table. If no match is found it leave the cell blank. The formula works when I type it manually into the worksheet then copy and paste down. The purpose for going the VBA route is that each month I get a new data sheet and I don't want to have to copy and paste the formula each month.

    Can anyone help me fix this?

    Thank you in advance.
    Last edited by mo4391; 03-09-2015 at 03:36 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Trouble with code containing nested vlookup

    try this:

    Sheets("Sunset_Query").Range("I2:I" & lr).FormulaR1C1 = _
    "=IF(IFERROR(VLOOKUP(RC[-3],Workshop,2,FALSE),"""""""")=""Core/Subcore"",""Core/Subcore"", IFERROR(VLOOKUP(RC[-2],Module,2,FALSE),""""""""))"

    though that macro alone is not likely to be faster than copying and pasting one formula from one workbook to another...
    Last edited by simarui; 03-09-2015 at 03:44 PM.
    Hope I could help - if your post has been solved don't forget to mark it as such.

    Clicking the * below is a great way to say thanks!

    "Drowning in 10 feet of water isn?t any different than drowning in a million feet. And if you can swim, it doesn?t matter how deep the ocean is. At some level, once you realize you?re in water that?s too deep to stand, you have to have a very different approach," - Joi Ito

  3. #3
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2013
    Posts
    142

    Re: Trouble with code containing nested vlookup

    Thanks for the quick response simarui. Your line was putting an " in the non-matching cells rather that leaving them blank. But I was able to figure out how to fix that one, so all works like a charm now. For what it's worth, this is actually much faster. Each month the new data is imported into the existing worksheet, so a simple keyboard shortcut for this macro and I'm done lickity-split.

    Thanks again for your help.

  4. #4
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Trouble with code containing nested vlookup

    well glad i could help. don't forget to mark it solved! and thanks for the rep!

+ 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. [SOLVED] Having trouble using a nested IF with VBA msgbox
    By msantucci in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-07-2015, 03:19 PM
  2. [SOLVED] Trouble with Nested If
    By shaught7 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 07-25-2014, 02:26 PM
  3. [SOLVED] Trouble with nested if/and statements
    By NamiSama in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-21-2014, 11:28 AM
  4. Trouble with Nested IF Function
    By gvishnu in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-25-2013, 05:18 PM
  5. Nested IF statement Trouble
    By mzbhvin in forum Excel General
    Replies: 6
    Last Post: 09-10-2009, 09:10 PM

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