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
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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
 
Upvote 0
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
 
Upvote 0
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%?
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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