PDA

View Full Version : [SOLVED:] Problems with vlookup on another sheet



slang
02-11-2019, 02:55 PM
OK, its been a while since I have done any coding and I must have lost a lot of brain cells in the last while. :)
I am having problems with qualifying the lsheet vlookup property. Doing something wrong

Sub removeprofiles()


Dim LastRow As Long
Dim terr As String
Dim crm As Integer
Dim current As Integer
Dim rang As Range
Dim i As Integer
Dim dSheet As Worksheet
Dim lSheet As Worksheet


Workbooks.Open Filename:="C:\BDR\33profiles.xls", Password:="offlimits1" 'this is the local workbook that needs to be verified
Set dSheet = Workbooks("33profiles.xls").Worksheets("sheet1")
Set lSheet = Workbooks("Assessment archive 2019.xlsm").Worksheets("accounts") 'this is the workbook withthe code in it

LastRow = dSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = LastRow To 2 Step -1

current = WorksheetFunction.VLookup(dSheet.Range("A" & i), dSheet.Range("A2:u3000"), 21, False)
crm = WorksheetFunction.VLookup(dSheet.Range("A" & i), lSheet.Range("A2:C3000"), 3, False)
If crm <> current Then MsgBox "Wrong at row " & I 'this is where I will do something
Next

End Sub

Paul_Hossler
02-11-2019, 03:12 PM
I think you need the workbook in the VLookup second parameter





Application.WorksheetFunction.VLookup(dSheet.Range("A" & I), Workbooks("Assessment archive 2019.xlsm").Worksheets("accounts").Range("A2:u3000"), 2, False)

slang
02-11-2019, 03:31 PM
oops, I needed a "on error resume next" as the vlookup will fail if it doesn't find a match.
Coding like a newbie , been a while