Darren Smith
Well-known Member
- Joined
- Nov 23, 2020
- Messages
- 631
- Office Version
- 2019
- Platform
- Windows
The code below seems to not be able to Vlookup the other workbook?
It says Run Time Error 1004 on this line??
It says Run Time Error 1004 on this line??
VBA Code:
JCM.Range("A4").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 40, 0)
Range("A4").Select
VBA Code:
Private Sub Fill_Details_From_Job_Record_Click()
TurnOff
Application.ScreenUpdating = False
Dim SrcOpen As Workbook, Des As Workbook
Dim JCM As Worksheet, TGSR As Worksheet, JobCard As Worksheet
Dim FilePath As String, Filename As String
Dim JobCardData As Range, SrcDataRange As Range
Dim LastRow As Long
FilePath = "\\tgs-srv01\share\ShopFloor\PRODUCTION\JOB BOOK\"
Filename = "JOB RECORD SHEET.xlsm"
Set SrcOpen = Workbooks.Open(FilePath & Filename)
Set TGSR = SrcOpen.Worksheets("TGS JOB RECORD")
LastRow = TGSR.Cells(TGSR.Rows.Count, "A").End(xlUp).Row
Set SrcDataRange = TGSR.Range("A2:AN" & LastRow)
Set JCM = ThisWorkbook.Worksheets("Job Card Master")
Set JobCard = ThisWorkbook.Worksheets("Job Card with Time Analysis")
' On Error GoTo ErrHandler
JCM.Range("A4").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 40, 0)
Range("A4").Select
JCM.Range("C4").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 8, 0)
Range("C4").Select
JCM.Range("D4").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 33, 0)
Range("D4").Select
JCM.Range("F6").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 18, 0)
Range("F6").Select
JCM.Range("A8").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 2, 0)
Range("A8").Select
JCM.Range("E8").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 3, 0)
Range("E8").Select
JCM.Range("G8").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 5, 0)
Range("G8").Select
JCM.Range("K10").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 7, 0)
Range("K10").Select
JCM.Range("K8").Value = Application.WorksheetFunction.VLookup(JCM.Range("G2"), SrcDataRange, 4, 0)
Range("K8").Select
JobCard.Range("A4").Value = Application.WorksheetFunction.VLookup(JobCard.Range("G2"), SrcDataRange, 40, 0)
Range("A4").Select
JobCard.Range("C4").Value = Application.WorksheetFunction.VLookup(JobCard.Range("G2"), SrcDataRange, 8, 0)
Range("C4").Select
JobCard.Range("D4").Value = Application.WorksheetFunction.VLookup(JobCard.Range("G2"), SrcDataRange, 33, 0)
Range("D4").Select
JobCard.Range("F6").Value = Application.WorksheetFunction.VLookup(JobCard.Range("G2"), SrcDataRange, 18, 0)
Range("F6").Select
JobCard.Range("A8").Value = Application.WorksheetFunction.VLookup(JobCard.Range("G2"), SrcDataRange, 2, 0)
Range("A8").Select
JobCard.Range("E8").Value = Application.WorksheetFunction.VLookup(JobCard.Range("G2"), SrcDataRange, 3, 0)
Range("E8").Select
JobCard.Range("G8").Value = Application.WorksheetFunction.VLookup(JobCard.Range("G2"), SrcDataRange, 5, 0)
Range("G8").Select
JobCard.Range("K10").Value = Application.WorksheetFunction.VLookup(JobCard.Range("G2"), SrcDataRange, 7, 0)
Range("K10").Select
JobCard.Range("K8").Value = Application.WorksheetFunction.VLookup(JobCard.Range("G2"), SrcDataRange, 4, 0)
Range("K8").Select
Application.DisplayAlerts = False
SrcOpen.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
'ErrHandler:
' If Err = 1004 Then
' MsgBox "Fill Job Number in Job Card Master Sheet Cell G2"
' End If
'
TurnOn
End Sub