VBA to stop macro based on Conditional Formatting fill

xrobc

New Member
Joined
Feb 25, 2015
Messages
27
Hi

I have a sheet with the following data in columns A, C and D (Column B is empty).


ABCD
QtyUMTUMS
3EAUN
4UNUN
1.5UNUN
1UNUN
0UNBT
0UNCN
1UNUN
1.5UNUN

<tbody>
</tbody>

<tbody>
</tbody>

I have conditional formatting to apply yellow fill when, A2 Does not Equal 0 and C2 does not equal D2, =IF(AND(C2<>D2,A2<>0)=FALSE,FALSE,TRUE).

I am looking for some help to write some VBA code to display a message and stop the macro when the above formula is true for any Row in Column C.

Please can you help?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Sorted this one myself in the end with the help of some other code I got from a previous post.

Code:
Sub CheckUM()

    Dim v, i As Long
    v = Range("G2:J" & Range("F" & Rows.Count).End(xlUp).Row).Value
    For i = 1 To UBound(v)
     If v(i, 3) <> v(i, 4) And v(i, 1) > 0 Then
             'Check for UM conflicts
              MsgBox ("You have Unit of Measure Confilcts." & vbNewLine & "Please Check and resolve before continuing"), vbCritical
              Range("G2:J2").Resize(UBound(v)).Value = v
              Exit Sub
        End If
    Next i
    Range("G2:J2").Resize(UBound(v)).Value = v


End Sub

This is the full version and not the version from where I was trying to work it out (so the columns are different)

I knew that there had to be a table involved somewhere, but could not figure it out yesterday.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,088
Messages
6,128,744
Members
449,466
Latest member
Peter Juhnke

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