VBA code giving error for VLOOKUP

Ayush_123

New Member
Joined
Apr 17, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I'm trying to implement automation in my office attendance workbook and for that i've written this code in between 2 sample sheets, attached are the 2 sheets in which i'm trying to take value from RAW_Data Sample Sheet from unique HRMS Id column and match that with Shrinkage_Sample Sheet HRMS Id Column and trying to update attendance in RAW sheet same as mentioned in the Shrinkage file.

So what i'm trying to do here is after defining fetch variable as variant, i'm trying to fetch the file from system with Application.GetOpenFileName function and store the file path in that variable and later i did tried to set this "fetch" variable with table 2 but it is not working

can you please help me with this code.
Attached are the file for RAW_Data and Shrinkage

VBA Code:
Sub attendance_module()
Dim raw As Workbook
Set raw = ActiveWorkbook


    Dim Imp_Row As Integer
    Dim Imp_Col As Integer
    Dim Table1 As Range
    Dim Table2 As Range
    Dim cl As Range
    Dim filename As Variant
    
    Set filename = Application.GetOpenFilename("Excel Files (*.xlsx),*.xlsx", 1, "Please select recent shrinkage", , True)
    
    
    Set Table1 = raw.Sheets("sheet1").Range("B2", Range("B2").End(xlDown))
    Set Table2 = fetch.Sheets("sheet1").Columns("A:G")
    
    
    Imp_Row = 2
    
    Imp_Col = 8
    
    For Each cl In Table1
        Cells(Imp_Row, Imp_Col) = Application.WorksheetFunction.VLookup(cl, Table2, 7, False)
        Imp_Row = Imp_Row + 1
        Table2.UsedRange.Copy Table1.Range("h:h")
    Next cl
    
    MsgBox "Done"
    
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I'm trying to Upload images but this shows me that the file uploaded is too large.
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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