+ Reply to Thread
Results 1 to 4 of 4

vlookup macro while comparing two column of differnt sheets

  1. #1
    Registered User
    Join Date
    03-05-2017
    Location
    New Zealand
    MS-Off Ver
    2013
    Posts
    29

    vlookup macro while comparing two column of differnt sheets

    Hi All,

    I am trying to using the vlookup formula as mentioned below.
    Sub Vlookup()
    Dim i As Integer

    For i = 2 To 155

    Range("B" & i) = Application.WorksheetFunction.Vlookup(Sheets("sheet1").Range("A" & i), Sheets("Sheet2").Range("A1:B155"), 1, False)

    Next i

    End Sub

    Data information

    Sheet1 data is present in sheet2.
    Sheet2 data is present in sheet1.
    Not all the data of sheet1 is in sheet2.
    And not all the data of sheet2 is in sheet1.



    Issue: when I am running the macro, it runs till the data which is not available at the sheet2.and then it give me an error 1004.

    I think when data is not matching the instead of getting #NA I getting this error which is stopping my macro with error.

    Could someone help me how to handle the #NA error in macro when I run the macro.
    Please see the attached file for your reference.

    Regards,

    Waqar
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,023

    Re: vlookup macro while comparing two column of differnt sheets

    Easiest way with the existing code:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,023

    Re: vlookup macro while comparing two column of differnt sheets

    Or, if you just want to check it's present, another way:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,023

    Re: vlookup macro while comparing two column of differnt sheets

    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] vlookup ? need help for comparing datas in different sheets
    By miki in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-15-2015, 12:42 AM
  2. Vlookup in different sheets comparing columns
    By azzyd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-25-2014, 11:25 PM
  3. Display same values in 3 differnt sheets.
    By rapsingekar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-05-2013, 11:30 AM
  4. Compare Two columns in differnt sheets
    By agarcia0742 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-13-2012, 09:42 AM
  5. VBA get value from differnt sheets
    By Rushdy Najath in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-29-2012, 09:44 AM
  6. Add up differnt variables in differnt named ranges
    By danielgri14 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-09-2011, 09:40 PM
  7. Macro to use time stamp from two differnt sheets and export row #
    By jblewis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2010, 01:36 PM

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