How to get Dim as Range to ignore #DIV/0!

Matt__S

New Member
Joined
Mar 26, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi,

I have the code below that works so long as there are no #DIV/0! errors in the column. What do I need to add to this code to have it ignore those errors?

Thanks!


Dim ramcel As Range
For Each ramcel In Range("E:E")
If ramcel.Value < 0.95 Then
ramcel.Font.Color = vbRed
ramcel.Interior.Color = 13617407
End If
Next
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,411
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Dim ramcel As Range
For Each ramcel In Range("E:E")
If Not IsError(ramcel) then
If ramcel.Value < 0.95 Then
ramcel.Font.Color = vbRed
ramcel.Interior.Color = 13617407
End If
end if
Next
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,346
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
   Dim ramcel As Range
   For Each ramcel In Range("E:E")
      If Not IsError(ramcel) Then
         If ramcel.Value < 0.95 Then
            ramcel.Font.Color = vbRed
            ramcel.Interior.Color = 13617407
         End If
      End If
   Next
 

Matt__S

New Member
Joined
Mar 26, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Unfortunately neither of these are working for me. It's looking at column 'E' in a pivot table and it doesn't seem to recognize the #DIV/0! as actual errors.

Can I explicitly tell excel to simply skip over cells that contain "#DIV0!"?

There are also cells in the column that are empty. Can I tell excel to skip both the DIVs and empty cells, only looking for an actual percentage x%?
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,411
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Unfortunately neither of these are working for me. It's looking at column 'E' in a pivot table and it doesn't seem to recognize the #DIV/0! as actual errors.

Can I explicitly tell excel to simply skip over cells that contain "#DIV0!"?

There are also cells in the column that are empty. Can I tell excel to skip both the DIVs and empty cells, only looking for an actual percentage x%?
I assume you have formulas in the col E cells, correct? If yes, then tell us what happens when you run the code. If there's an error, what line is highlighted, what's the error message, and what's the address of ramcel at that point?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,164
Messages
5,623,109
Members
415,955
Latest member
ssheldon2021

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
Top