Good afternoon,
I'm attempting to use a VLookup macro to find data in a different sheet, within the same workbook. Oddly enough it was working until it didn't find two matches, then it stopped working. I've tried several ways to edit it - initially I had the source data in a different workbook then moved it to the same workbook, along with other attempts. Still, I can't get it to work. Any help would be appreciated.
The intended use is = that i enter the initial id number in column A and when i run the macro, all of the other fields autofill but right now nothing happens. This is my code:
i'm using Excel Office16 Windows
Sub Lookup()
Dim lRow As Integer
Dim wb As Workbook
Set wb = ActiveWorkbook
ThisWorkbook.Activate
Dim i As Integer
lRow = Cells(Rows.Count, 2).End(xlUp).Row
For i = 2 To lRow
If Len(Cells(i, 1)) < 5 Then
Range("a" & i).Value = Format(Date, "mm/dd/yyyy")
End If
If Not IsEmpty(Range("b" & i).Value) Then
Range("b" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 2, 0)
Range("c" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 3, 0)
Range("d" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 4, 0)
Range("e" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 5, 0)
Range("f" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 6, 0)
Range("g" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 7, 0)
End If
Next i
End Sub
I'm attempting to use a VLookup macro to find data in a different sheet, within the same workbook. Oddly enough it was working until it didn't find two matches, then it stopped working. I've tried several ways to edit it - initially I had the source data in a different workbook then moved it to the same workbook, along with other attempts. Still, I can't get it to work. Any help would be appreciated.
The intended use is = that i enter the initial id number in column A and when i run the macro, all of the other fields autofill but right now nothing happens. This is my code:
i'm using Excel Office16 Windows
Sub Lookup()
Dim lRow As Integer
Dim wb As Workbook
Set wb = ActiveWorkbook
ThisWorkbook.Activate
Dim i As Integer
lRow = Cells(Rows.Count, 2).End(xlUp).Row
For i = 2 To lRow
If Len(Cells(i, 1)) < 5 Then
Range("a" & i).Value = Format(Date, "mm/dd/yyyy")
End If
If Not IsEmpty(Range("b" & i).Value) Then
Range("b" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 2, 0)
Range("c" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 3, 0)
Range("d" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 4, 0)
Range("e" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 5, 0)
Range("f" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 6, 0)
Range("g" & i).Value = WorksheetFunction.VLookup(Range("a" & i).Value, Sheets("Phone List").Range("A2:G12"), 7, 0)
End If
Next i
End Sub