+ Reply to Thread
Results 1 to 4 of 4

Add two VLOOKUP results together in VBA

  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    2

    Add two VLOOKUP results together in VBA

    I'm not too familiar with VBA. I have a macro which returns the results for

    =IF(ISNA(VLOOKUP("EMPLOYEE",Z:AA,2,0)),0,VLOOKUP("EMPLOYEE",Z:AA,2,0))

    As of today, the entry EMPLOYEE is sometimes written as it was—EMPLOYEE, and sometimes as EMP. I have to add these two together. How do I change the code of the macro?

    Before it was:

    ActiveCell.FormulaR1C1 = _
    "=IF(ISNA(VLOOKUP(""[EMPLOYEE"",C[-16]:C[-14],2,0)),0,VLOOKUP(""EMPLOYEE"",C[-16]:C[-14],2,0))"

    I tried "=IF(ISNA(VLOOKUP(""EMPLOYEE"",C[-16]:C[-14],2,0)),0,VLOOKUP(""EMPLOYEE"",C[-16]:C[-14],2,0))"+"IF(ISNA(VLOOKUP(""EMP"",C[-16]:C[-14],2,0)),0,VLOOKUP(""EMP"",C[-16]:C[-14],2,0))"

    as I would in Excel, but of course it doesn't work. Any help would be appreciated.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Add two VLOOKUP results together in VBA

    Maybe:

    =IF(ISNA(VLOOKUP("*" & "EMP" & "*",Z:AA,2,0)),0,VLOOKUP("*" & "EMP" & "*",Z:AA,2,0))

  3. #3
    Registered User
    Join Date
    08-01-2012
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Add two VLOOKUP results together in VBA

    Thanks for taking the time to answer. I think I didn't make myself clear. I have two columns, Z and AA. Z is alpha and AA is numeric. I have to aggregate column AA for all the appearances of 'EMP' and of 'EMPLOYEE' in column Z throughout the 200,000 rows of the report. My macro only looked for 'EMPLOYEE' until now, but as of today, the report uses EMP and EMPLOYEE interchangably, and I have to combine the totals for EMP and EMPLOYEE in my report. I have the same issue with five more terms which have been shortened (CORP and CORPORATE, EDU and EDUCATION, etc.), and I have to add together the long form and the short form when aggregating.

    It's a long and complicated macro, so I was wondering if someone can tell me how to replace the VBA code of that VLOOKUP so that it will not only look for EMPLOYEE, but rather it will add all appearnces of both EMP and EMPLOYEE.

  4. #4
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Add two VLOOKUP results together in VBA

    Quote Originally Posted by irv View Post
    Thanks for taking the time to answer. I think I didn't make myself clear. I have two columns, Z and AA. Z is alpha and AA is numeric. I have to aggregate column AA for all the appearances of 'EMP' and of 'EMPLOYEE' in column Z throughout the 200,000 rows of the report. My macro only looked for 'EMPLOYEE' until now, but as of today, the report uses EMP and EMPLOYEE interchangably, and I have to combine the totals for EMP and EMPLOYEE in my report. I have the same issue with five more terms which have been shortened (CORP and CORPORATE, EDU and EDUCATION, etc.), and I have to add together the long form and the short form when aggregating.

    It's a long and complicated macro, so I was wondering if someone can tell me how to replace the VBA code of that VLOOKUP so that it will not only look for EMPLOYEE, but rather it will add all appearnces of both EMP and EMPLOYEE.
    Sure... but do you need it to be a Vlookup Formula? Or can you just have it be the Vlookup RESULT in the macro?

    Please Login or Register  to view this content.
    That may need a little alteration, but should put you on your way. I've never used the C[-16]:C[-14] syntax before.
    Going for Guru! Click the Star to the bottom left of this post if I helped!

+ 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. Using vLookup based on results from a vLookup & returning an undetermined list
    By NormalityBan in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 08-14-2014, 05:02 AM
  2. if vlookup yields no results then try another vlookup
    By IronCladRooster in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-07-2014, 04:00 PM
  3. [SOLVED] Using VLookup but results show formula instead of results...
    By excel me in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 11-28-2013, 09:40 PM
  4. VLookup that Results with False or Blank Results
    By mycon73 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-12-2013, 07:16 PM
  5. Worksheet function Vlookup and VLOOKUP return different results
    By zandero in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-08-2010, 08:24 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