VBA getting rid of #N/A

tintinoo7

New Member
Joined
Dec 5, 2018
Messages
2
Hi

I have the following code that works fine, but if the Data in Sheet "Data" does not have a match it returns #N/A. I tried code to find text and change cell colour but it does not find #N/A. The next bit of code is a copy and paste special (values) so I have got rid of the formula in the cells. Please help me either come up with a way to remove #N/A and replace it with a cell highlighted yellow or just a way to get rid on #N/A. Thanks

With ThisWorkbook.Worksheets("Imp")

.Range("G2:G" & lr) = "=VLOOKUP(E2,Data!E:G,2,FALSE)"
.Range("H2:H" & lr) = "=VLOOKUP(E2,Data!E:G,3,FALSE)"
.Range("I2:I" & lr) = "=VLOOKUP(B2,B:B,1,FALSE)"

End With
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi & welcome to MrExcel
This will remove the errors
Code:
.Range("G2:G" & Lr) = "=VLOOKUP(E2,Data!E:G,2,FALSE)"
.Range("H2:H" & Lr) = "=VLOOKUP(E2,Data!E:G,3,FALSE)"
.Range("I2:I" & Lr) = "=VLOOKUP(B2,B:B,1,FALSE)"
[COLOR=#0000ff].Range("G2:I" & Lr).SpecialCells(xlFormulas, xlErrors).ClearContents
[/COLOR]
 
Upvote 0
Fluff

Thank you so much what an incredible response time.

Now how to make the empty cells highlighted as yellow?

Regards

tintinoo7
 
Upvote 0
Add this line
Code:
[COLOR=#0000ff].Range("G2:I" & Lr).SpecialCells(xlFormulas, xlErrors).Interior.Color = vbYellow[/COLOR]
.Range("G2:I" & Lr).SpecialCells(xlFormulas, xlErrors).ClearContents
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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