VBA code for Vlookup to a different worksheet

mikenelena

Board Regular
Joined
Mar 5, 2018
Messages
139
Office Version
  1. 365
Platform
  1. Windows
Hello,

In an existing workbook I have a sheet ("Main") with 7 columns of data. Column 1 contains a file number.

I generate (by a query from Access) a new workbook & sheet containing the 8 columns of data. The first 6 of which are the same as in the Main workbook. I currently use a vlookup function to determine which claim numbers (and of course the corresponding data are on the new worksheet but NOT already in the Main workbook.

Presently I run this vlookup in Column G and copy the formula down. Then I highlight the column and past the values, filter by those values (I am after the ones with "N/A") and then create a new worksheet and copy/paste all of the N/A values in there. I would like to automate this with some VBA code. I have found and tested the following code which produces no errors, but no data results either. (I realize this particular code wouldn't do everything I need, but I figured it would get me started.) Can anyone offer any insight as to why this code is not working?

Any help would be MUCH appreciated! Thanks!!

Code:
Sub ImpFPQ()


    On Error Resume Next




    Dim Imp_Row As Integer
    Dim Imp_Col As Integer
    Dim Table1 As Range
    Dim Table2 As Range
    Dim cl As Range
    
    Set Table1 = Range("A2", Range("A2").End(xlDown))
    
    Set Table2 = Workbooks("Test.xlsm").Sheets("Main").Columns("A:G")
    
    Imp_Row = 2
    
    Imp_Col = 7
    
    For Each cl In Table1
        Cells(Imp_Row, Imp_Col) = Application.WorksheetFunction.VLookup(cl, Table2, 1, False)
        Imp_Row = Imp_Row + 1
    Next cl
    
    MsgBox "Done"
    
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,091
Latest member
gaurav_7829

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top