remove #NA from VLookup macro result...?

blist

New Member
Joined
Mar 11, 2004
Messages
20
My Lookup value range contains many blank cells I'd like to remain blank. This code works to populate that range as needed, but the blank cells all show a #NA result. How can I edit this (or another?) macro to leave the blank cells empty?

Code:
Sub EQL_Lookup()
Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row

With WorksheetFunction

     Range("L2:P" & LastRow).Value = .VLookup(Range("L2:P" & LastRow), Sheets(13).Range("A1:C" & LastRow), 2, False)
    
End With
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try

Code:
Sub EQL_Lookup()
Dim LastRow As Long, x As Variant
LastRow = Range("A" & Rows.Count).End(xlUp).Row
 
With Application
    x = .VLookup(Range("L2:P" & LastRow), Sheets(13).Range("A1:C" & LastRow), 2, False)
 
    If Iserror(x) Then 
        Range("L2:P" & LastRow).Value = ""
    Else
        Range("L2:P" & LastRow).Value = x
    End If
End With
End Sub
 
Upvote 0
I don't have the range for the lookup so I can't test this

Code:
Sub EQL_Lookup()
Dim LastRow As Long
Dim V As Variant
LastRow = Range("A" & Rows.Count).End(xlUp).Row
With WorksheetFunction
  V = .VLookup(Range("L2:P" & LastRow), Sheets(13).Range("A1:C" & LastRow), 2, False)
  If V = "#NA" Then V = ""
  
  Range("L2:P" & LastRow).Value = V
    
End With
End Sub
 
Upvote 0
Thanks to all...

jonmo1, I got the same result with your code as mine...lookup value range correctly populated with titles, and all blank cells still show #NA.

Jeffery Smith, your code showed a Type Mismatch at the highlight below when run. My edits are strictly guesses, and I haven't been able to make it work yet.

Code:
Sub EQL_Lookup()
Dim LastRow As Long
Dim V As Variant
LastRow = Range("A" & Rows.Count).End(xlUp).Row
     With WorksheetFunction
      V = .VLookup(Range("L2:P" & LastRow), Sheets(13).Range("A1:C" & LastRow), 2, False)
 [highlight] If V = "#NA" Then[/highlight] V = "" 
  
     Range("L2:P" & LastRow).Value = V
    
End With
End Sub
 
Upvote 0
and all blank cells still show #NA

I don't understand.
The posted code only does 1 single vlookup...what do you mean ALL...All of what?


Something tells my you've posted a "simplified" version of your actual code.

Can you post your actual complete code?
And a detailed explaination of what you want to do?
 
Last edited:
Upvote 0
This is kind of clunky, but it works

Code:
Sub EQL_Lookup()
Dim LastRow As Long
Dim V As Variant
LastRow = Range("A" & Rows.Count).End(xlUp).Row
     With WorksheetFunction
      On Error GoTo NoVal
      V = .VLookup(Range("L2:P" & LastRow), Sheets(13).Range("A1:C" & LastRow), 2, False)
  
     Range("L2:P" & LastRow).Value = V
    
End With
Exit Sub
: NoVal
Range("L2:P" & LastRow).Value = ""
End Sub
 
Upvote 0
jonmo1, my apologies for any misunderstandings...

I indeed posted the complete code. As stated in my original post, my Lookup value range contains many blank cells I'd like to remain blank. This code works to populate that range as needed, but the originally blank cells (before running the posted code) all show a #NA result after running the code.

Many thanks for your time and trouble!
 
Upvote 0
OK, think I get it..

Try

Code:
Sub EQL_Lookup()
Dim LastRow As Long, x As Variant

LastRow = Range("A" & Rows.Count).End(xlUp).Row
For Each c In Range("L2:P" & LastRow)
    x = Application.VLookup(c, Sheets(2).Range("A1:C" & LastRow), 2, False)
    If Not IsError(x) Then c.Value = x
Next c
End Sub
 
Upvote 0
Jeffrey Smith, thanks. At the red highlight, VBE says Sub or Function not defined. What does that ": NoVal" phrase mean or refer to in this context...?

Code:
Sub EQL_Lookup()
Dim LastRow As Long
Dim V As Variant
LastRow = Range("A" & Rows.Count).End(xlUp).Row
     With WorksheetFunction
      On Error GoTo NoVal
      V = .VLookup(Range("L2:P" & LastRow), Sheets(13).Range("A1:C" & LastRow), 2, False)
  
     Range("L2:P" & LastRow).Value = V
    
End With
Exit Sub
: [highlight]NoVal[/highlight]
Range("L2:P" & LastRow).Value = ""
End Sub
 
Upvote 0
Sorry, the colon is in the wrong place. And I forgot to resume next. Always in a hurry to get my post up because there are so many people willing to help.

Code:
Sub EQL_Lookup()
Dim LastRow As Long
Dim V As Variant
LastRow = Range("A" & Rows.Count).End(xlUp).Row
  With WorksheetFunction
    On Error GoTo NoVal
    Range("L2:P" & LastRow).Value = .VLookup(Range("L2:P" & LastRow), Sheets(13).Range("A1:C" & LastRow), 2, False)
  End With
Exit Sub
: NoVal
Range("L2:P" & LastRow).Value = ""
Resume Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top