Need help with ISNA

instanceoftime

Board Regular
Joined
Mar 23, 2011
Messages
103
I would like to program a macro (actually include in current marco) to do the following.

The following code searches a master file looking for associated prices. However there is a possibility that A1 doesn't contain the number looked for.
This gives me the #NA error in the cell. I would like to go down column E and change the #NA to zero.

Code:
Sub pricing()
'
' pricing Macro
'
' Keyboard Shortcut: Ctrl+u
'


Dim lr As Long




    lr = Cells(Rows.Count, "A").End(xlUp).Row  
    
    Range("E1:E" & lr).Formula = "=VLOOKUP(A1,[final.xls]Items!$A$1:$H$40000,8,0)"[COLOR=#ff0000] 'this fetches price from a different workbook and places value in column E in the current workbook[/COLOR]


    [COLOR=#ff0000]'I want to go down column E and change [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=NA]#NA[/URL]  to zero[/COLOR]


End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I would like to program a macro (actually include in current marco) to do the following.

The following code searches a master file looking for associated prices. However there is a possibility that A1 doesn't contain the number looked for.
This gives me the #NA error in the cell. I would like to go down column E and change the #NA to zero.

Code:
Sub pricing()
'
' pricing Macro
'
' Keyboard Shortcut: Ctrl+u
'


Dim lr As Long




    lr = Cells(Rows.Count, "A").End(xlUp).Row  
    
    Range("E1:E" & lr).Formula = "=VLOOKUP(A1,[final.xls]Items!$A$1:$H$40000,8,0)"[COLOR=#ff0000] 'this fetches price from a different workbook and places value in column E in the current workbook[/COLOR]


    [COLOR=#ff0000]'I want to go down column E and change [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=NA"]#NA[/URL]  to zero[/COLOR]


End Sub


Why don't you just use "IFERROR"? (See mod in blue.)

Code:
Range("E1:E" & lr).Formula = "=[COLOR=#0000ff]IFERROR([/COLOR]VLOOKUP(A1,[final.xls]Items!$A$1:$H$40000,8,0)[COLOR=#0000ff],0)[/COLOR]"[COLOR=#ff0000] 'this fetches price from a different workbook and places value in column E in the current workbook
[/COLOR]

HTH
 
Upvote 0
awesome, I was looking into how to wrap it in IFERROR as well but both are beyond me. Thanks .... Your solution worked perfect!
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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