Good morning. I am using VBA to VLOOKUP data between two worksheets. I cannot figure out what I'm doing wrong. Anyone have an idea? Thanks!
The worksheet with the keys and data is "Project Mapping" (sorry, I get a 'forbidden' when trying to upload a screenshot.
- Column A: "Node ID" with a value of 1234567
- Column B: "Project ID" with a value of ProjectXYZ
The worksheet that contains "Node ID", "Resource Name", and "Project ID" is "Imported Data".
- Column A: "Resource Name" with a value of Jimbob
- Column C: "Project ID" which is where VLOOKUP will lookup the "Project ID" associated with "Node ID".
- Column N: "Node ID" with a value of 1234567
Sub map_Node_ID_to_Project_ID()
'Declare variables
Dim IDSheet As Worksheet
Dim PMSheet As Worksheet
Dim DRange As Range
Set IDSheet = ThisWorkbook.Worksheets("Imported Data")
Set PMSheet = ThisWorkbook.Worksheets("Project Mapping")
IDLastRow = IDSheet.Range("J" & Rows.Count).End(xlUp).Row
PMLastRow = PMSheet.Range("B" & Rows.Count).End(xlUp).Row
Set DRange = PMSheet.Range("A2:B" & PMLastRow)
For x = 2 To IDLastRow
On Error Resume Next
IDSheet.Range("C" & x).Value = Application.WorksheetFunction.VLookup( _
IDSheet.Range("J" & x).Value, DRange, 2, False)
Next x
End Sub