Get rid of #N/A

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
HI,

The following formula in the worksheet module displays #N/A when no match can be found.

Code:
Me.Cells(nextRow, "H").Formula = "=VLOOKUP(C" & nextRow & _
                    ",'Price Range'!A4:K51,11 ,FALSE)"

How could I make the formula not to display the #N/A even no match can be found. Instead leave the column blank.

Any help on this would be kindly appreciated.

Thanks in advance.
 
Is this the final code mentioned by you; Tuelor?

Code:
Me.Cells(nextRow, "H").Formula = "=IFERROR(VLOOKUP(C" & nextRow & _
                    ",'Price Range'!A4:K51,11 ,FALSE,"")"
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
But could you define me why you said "it also looks inefficient"?

It's not the formula that appears inefficient, but the code.

Without seeing the full code and knowing what it is you're trying to do it's impossible to say for definite, it's just an opinion based on that line of code.

Immediate observation is that the code will be running far more often than is required.
 
Upvote 0
What I'm trying to do is when the user writes a value in column C of the active sheet, the value related to the value in column C to get copied from the column 11 of the sheet Price range and place it in column H of the active sheet.

If the user writes a value in column C of the active sheet; where this value does not exits in price range sheet I want the column H of the active sheet not to display anything ( meaning not to display the #N/A)

I hope you've now understood my intention.
 
Upvote 0
And there lies the error in my observation, I saw the variable "nextRow" as a loop, rewriting multiple formula, when it is only writing one.

You could alternatively make use of the Target variable and use something like

Code:
Target.Offset(, 5).FormulaR1C1 = "=IFERROR(VLOOKUP(RC3,'Price Range'!R4C1:R51C11,11 ,0,"""")"

Personally I find this method easier when working with formula in code, though it can prove confusing for anyone that doesn't understand R1C1.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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