tinydancer
New Member
- Joined
- Jun 15, 2016
- Messages
- 44
I have a macro that runs a vlookup. It's tailored not to overwrite cells that already have text in them and only carry over found values to blank cells. At the moment it simply goes looking for these values on another sheet in the same workbook called "Lookup_Sheet".
What I want is to be able to run the code and let me select the file the vlookup pulls from. Essentially it would take me to My Computer and I would click on the excel workbook I want and then I would select the exact worksheet that I want to use for the vlookup. I would really appreciate any and all help I can get on this one.
Code:
Sub Vlookup44()
Dim i As Integer
Dim stVal As String
Dim lastRow As Long
On Error GoTo err_handler
lastRow = Range("E" & Rows.Count).End(xlUp).Row
For i = 2 To lastRow
If IsEmpty(Range("Q" & i)) Then
stVal = Application.WorksheetFunction.Vlookup(Range("E" & i).Value, Sheets("Lookup_Sheet").Range("E:T"), 13, False)
On Error Resume Next
Range("Q" & i) = stVal
End If
If IsEmpty(Range("R" & i)) Then
stVal = Application.WorksheetFunction.Vlookup(Range("E" & i).Value, Sheets("Lookup_Sheet").Range("E:T"), 14, False)
On Error Resume Next
Range("R" & i) = stVal
End If
If IsEmpty(Range("S" & i)) Then
stVal = Application.WorksheetFunction.Vlookup(Range("E" & i).Value, Sheets("Lookup_Sheet").Range("E:T"), 15, False)
On Error Resume Next
Range("S" & i) = stVal
End If
If IsEmpty(Range("T" & i)) Then
stVal = Application.WorksheetFunction.Vlookup(Range("E" & i).Value, Sheets("Lookup_Sheet").Range("E:T"), 16, False)
On Error Resume Next
Range("T" & i) = stVal
End If
Next
Exit Sub
err_handler:
MsgBox Err.Description
End Sub
What I want is to be able to run the code and let me select the file the vlookup pulls from. Essentially it would take me to My Computer and I would click on the excel workbook I want and then I would select the exact worksheet that I want to use for the vlookup. I would really appreciate any and all help I can get on this one.