Use AND Formula in VBA

tatertot

New Member
Joined
Apr 10, 2016
Messages
31
I created a conditional format in my report to fill the cell in red when this formula = TRUE.

[TABLE="width: 65"]
<tbody>[TR]
[TD="class: xl71, width: 65"]=AND(B16<>B17,B16<>"",B17<>"")

How do I apply this into a macro? I am adding a validation button that will confirm that this AND formula has been corrected. People will see the red but sometimes keep right on working through the report. I want the validation to stop them and make them change the cells value so the AND formula = FALSE.

I have zero idea where to start. The cell I want to "validate" is "B16". Thanks all!!![/TD]
[/TR]
</tbody>[/TABLE]
 
Hello All,

I currrently have the following code:

Code:
Private Sub CommandButton1_Click()

  Dim r As Range
  Set r = Range("H23:I27")
    If WorksheetFunction.Sum(r) <> 0 Then
        MsgBox "Your data does not balance."
    Else
        MsgBox "Your Template align.  Please proceeed"
    End If
    
  Dim r1 As Range
  Set r1 = Range("K23:L27")
    If WorksheetFunction.Sum(r1) <> 0 Then
        MsgBox "Upload does not align with Template.  Please review all submitted data."
    Else
        MsgBox "Upload = Upload Template.  Complete!"
    End If
    
    
End Sub

Now I am wanting to add this validation of cost centers in cells B16 & B17. Both cells have data validation in them using the INDIRECT formula from another drop-down list to limit risk of using inapproproate cost centers. But the user could select cost center 100 for B16 and cost center 150 for B17. This will cause error in there upload. That is why I currently have conditional format to highlight the cells red when the cost centers do not align.

My aspirations with the code is to just create a pop-up like the other code I have do to state "Cost centers do not align. Please review before proceeding.". Is there anyway to just have the code say if cells b16 & B17 are filled with the color red, then MsgBox appears?

Does this help create a clearer picture?
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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