Consulting

Results 1 to 2 of 2

Thread: iserror and lookup not working combined

  1. #1

    iserror and lookup not working combined

    hi

    the below code is not working, the second part of the sub works fine, somehow the first part return NA errors in my sheet, which shouldnt happen



    actually im just trying to do the following: see if a value in cell XX can be found in column (YY) ,

    if found in that column do the vlookup " Cells(21 + i, 37).Value = Application.VLookup(Cells(21 + i, 31), Sheets("data").Range("ai"), 12, False)

    if it is not found in column (YY) it means it should be found in column (zz)

    so then lookup " Cells(21 + i, 37).Value = Application.VLookup(Cells(21 + i, 31), Sheets("data").Range("aj"), 11, False) "

    ---- note : this is the first step of the program, it is a bit more complex , because if the value Cells(21 + i, 31) is not found in both column YY or ZZ it should in fact lookup the (21 + i, 31) in the same columns , then perform the same lookups...


    any help on either the first part of the sub or the full sub?


    edit i added the sheet so maybe some would be kind enough to help me



    Sub oldhome_home()
    
    
    
    
    
    Dim i As Integer
    i = 1
     
    
    
    ' nota ik ga hier de sub nesten dus bij NA eerst kijken naar -2, dan naar de -1
    
    
    If IsError(Application.VLookup(Cells(21 + i, 31), Sheets("data").Range("ai:aw"), 12, False)) Then
    
    
    Do While Cells(21 + i, 31).Value <> ""
    Cells(21 + i, 37).Value = Application.VLookup(Cells(21 + i, 31), Sheets("data").Range("aj:aw"), 11, False)
    
    
         i = i + 1
    Loop
    
    
    Else
    
    
    Do While Cells(21 + i, 31).Value <> ""
    Cells(21 + i, 37).Value = Application.VLookup(Cells(21 + i, 31), Sheets("data").Range("ai:aw"), 12, False)
    
    
    
    
         i = i + 1
        
     Loop
        
        
        
        
      End If
    End Sub
    Attached Files Attached Files

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why don't you tell us in words what you are trying to do, rather than with your code which doesn't work as you say.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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