VBA to find #N/A in column

aaleem

Board Regular
Joined
Sep 26, 2014
Messages
56
Office Version
  1. 2016
Hi,

im trying to amend an existing code to find the text "#N/A" in column L then go for the Vlookup.

while doing so im getting the Method 'Range' of object_Global failed error.

please see below the code

VBA Code:
With ws1
        lLastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
        arr = .Range("A2:M" & lLastRow)
        For i = LBound(arr) To UBound(arr)
            
            If Range(arr(i, 12)).Text = "#N/A" Then
            If Len(arr(i, 1)) > 0 Then

                arr(i, 13) = Application.VLookup(arr(i, 1), ws3.Range("A:C"), 3, False)
            End If
        End If
    Next
    .Range("M1:M" & lLastRow) = Application.Index(arr, 0, 13)
    End With

any suggestion will be highly appreciated.
thanks,
Aleem
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try
VBA Code:
If arr(i, 12) = "#N/A" Then
 
Upvote 0
Try
VBA Code:
If arr(i, 12) = "#N/A" Then
Thank you so much Fluff for your time, i tried the above line im getting the Type mismatch error on the rows where #N/A values are there in column L.
 
Upvote 0
Will you have any error values in col L other than #N/A & if so do you want to still do the vlookup?
 
Upvote 0
Will you have any error values in col L other than #N/A & if so do you want to still do the vlookup?
HI Fluff, i have text values including #N/A and blank rows, no other errors on column L.
 
Upvote 0
In that case try
VBA Code:
If IsError(arr(i, 12)) Then
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,537
Messages
6,125,393
Members
449,222
Latest member
taner zz

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