Highlighting Values of a Cell when the Cell contains #N/A

wao5012

New Member
Joined
May 7, 2018
Messages
32
Hello All,

I am using the below script to highlight values of cells in a specific column when they contain #N/A. I recieve an error called "Type Mismatch" on the highlighted line below (in Red).
Sub highlightValues()


Sub highlightValues()


Dim ws As Worksheet
Dim i As Long
Dim lastrow As Long
Set ws = Worksheets("sheet1")
lastrow = ws.Cells(Rows.Count, 1).End(xlUp).Row


For i = 3 To lastrow
If Cells(i, 18).Value = "#N/A" Then
Cells(i, 18).Interior.Color = RGB(256, 256, 256)
Else
Cells(1, 18).Interior.Color = xlNone
End If
Next


End Sub
 
Rick to give you some background. I built out a VBA code that performs a vlookup to return values (in formula form), then i copy and past the values as values. I just want to find where cell equals #N/A highlight red. i shouldn't get any other error so i am sure i don't need the specific error.
Bearing in mind the part in red try
Code:
Columns("R").SpecialCells(xlConstants, xlErrors).Interior.Color = vbRed
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Bearing in mind the part in red try
Code:
Columns("R").SpecialCells(xlConstants, xlErrors).Interior.Color = vbRed
I completely missed the "then i copy and past the values as values" part of the OP's post.:banghead:

By the way, you should add the On Error trap I show in Message #10 in case there are no errors.
 
Last edited:
Upvote 0
The column is Column R. As stated earlier prob need to clarify i have a VBA code that performs and vlookup and then copay and paste column R to give me values. So there are no formulas and no errors in the cells. When you copy and paste values the "#N/A" is the pasted value of the error.
 
Upvote 0
Scratch my last comment. Thank you Rick and Fluff for your input as i run the code with those couple lines it works. Thanks for your help it is appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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