Consulting

Results 1 to 3 of 3

Thread: Problems with vlookup on another sheet

  1. #1
    VBAX Regular
    Joined
    Apr 2008
    Posts
    97
    Location

    Angry Problems with vlookup on another sheet

    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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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)
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Apr 2008
    Posts
    97
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •