Skipping an iteration if there is a mismatch error.

aellington287

New Member
Joined
Mar 7, 2016
Messages
7
I have programmed some conditional formatting using VBA, comparing the values of 2 cells in many iterations. The issue is that some of my coworkers do not understand that in order for these numbers to be compared, they must have the same format. Some of them have put words in one of the cells and then....you guessed it, they got a mismatch error which gives them the option to debug the program. What line of code can I use to skip an iteration if the cells are mismatched? Here is an example from my code:

For i = 5 To 49
For j = 15 To 26
If Cells(i, 30) = "greater than or equal" Then
***
If Cells(i, j) >= Cells(i, 12) - (Cells(i, 12) * 0.1) And Cells(i, j) < Cells(i, 12) Then Cells(i, j).Interior.Color = RGB(250, 225, 50)
If Cells(i, j) >= Cells(i, 12) Then Cells(i, j).Interior.Color = RGB(100, 250, 100)
If Cells(i, j) < Cells(i, 12) - (Cells(i, 12) * 0.1) Then Cells(i, j).Interior.Color = RGB(250, 100, 100)
If Cells(i, j) = "" Then Cells(i, j).Interior.ColorIndex = 0

This line of code would need to be entered where I have placed the three asterisks. Any help would be appreciated.
 

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.
Perhaps.
Code:
For i = 5 To 49
    For j = 15 To 26

        If Cells(i, 30) = "greater than or equal" Then
            If IsNumeric(Cells(i,j).Value) And IsNumeric(Cells(i,12).Value Then

                If Cells(i, j) >= Cells(i, 12) - (Cells(i, 12) * 0.1) And Cells(i, j) < Cells(i, 12) Then Cells(i, j).Interior.Color = RGB(250, 225, 50)
                If Cells(i, j) >= Cells(i, 12) Then Cells(i, j).Interior.Color = RGB(100, 250, 100)
                If Cells(i, j) < Cells(i, 12) - (Cells(i, 12) * 0.1) Then Cells(i, j).Interior.Color = RGB(250, 100, 100)
                If Cells(i, j) = "" Then Cells(i, j).Interior.ColorIndex = 0

            End If
        End If

    Next j
Next I
 
Upvote 0

Forum statistics

Threads
1,215,172
Messages
6,123,428
Members
449,099
Latest member
COOT

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