Need to take detail from a workbook using a vlookup function

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
When i click the list box on "Fill Details" nothing happens???

VBA Code:
    If ListBox4 = "Fill Details" Then
            
    On Error GoTo ErrHandler
    Application.ScreenUpdating = False
    
    Dim src As Workbook
    Dim JCM As Worksheet
    
    
    Set src = Workbooks.Open("\\TGS-SRV01\Share\ShopFloor\PRODUCTION\JOB BOOK\JOB RECORD SHEET.xlsm", True, True)
    Set JCM = Worksheets("Job Card Master")
    
    Dim iTotalRows As Integer
    iTotalRows = src.Worksheets("sheet1").Range("A1:A" & Cells(rows.Count, "A").End(xlUp).row).rows.Count
   
   
    Dim iCnt As Integer
    For iCnt = 2 To iTotalRows
        Sheet1.Cells("40" & iCnt) = Application.WorksheetFunction.VLookup(JCM.Cells("G2"), _
        Sheets(JCM).Range("G2"), iCnt, 0)
    Next iCnt
    

    src.Close False
    Set src = Nothing
    
ErrHandler:
    Application.EnableEvents = True
    Application.ScreenUpdating = True

MsgBox "Successfully entered Job Book data to Job Card Master Headers"

End If 

End sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You’ll need a method to trigger the code to run. For example a worksheet change event by adding the following to the start of your VNA code.
Private Sub Worksheet_Change(ByVal Target As Range)
 
Upvote 0
Safe to assume that you’re putting this code in the particular sheet it pertains to rather than ThisWorkbook?
 
Upvote 0
Perhaps this section needs to be updated...try the following:

For iCnt = 2 To iTotalRows
Worksheets("Sheet1").Cells("40" & iCnt) = Application.WorksheetFunction.VLookup(JCM.Cells("G2"), _
Worksheets(JCM).Range("G2"), iCnt, 0)
Next iCnt
 
Upvote 0

Forum statistics

Threads
1,215,717
Messages
6,126,422
Members
449,314
Latest member
MrSabo83

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