display message box when cell color is red

kiwikiki718

Board Regular
Joined
Apr 7, 2017
Messages
80
Office Version
  1. 365
Platform
  1. Windows
I have a cell with conditional formatting to turn red when a certain condition is met. is there a VBA code that will display a message box stating duplicate based on a cell color? so what I need is when a cell turns red, a message box to appear showing duplicate.

here is the code I have but it does not seem to work

Sub Duplicate_Class() 'Duplicate Check'
Dim ws As Worksheet
Set ws = Sheets("Request")
If ws.Range("C8").Interior.Color = RGB(255, 0, 0) Then
MsgBox "Duplicate class!"
End If
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Rather than trying to work off of color changes by Conditional Formatting, which is not that easy, why not just use the same condition you are using for Conditional Formatting in VBA code?

If you put it in a Worksheet_Change event procedure, the code will automatically run when certain cells are manually updated.
If you need help with this code, please provide the following:
- The range of your data
- The Conditional Formatting rule
- How data is changed that should trigger this to run (i.e. what cells are being updated and how)
 
Upvote 0
Try:-
Code:
Sub Duplicate_Class() 'Duplicate Check'
 Dim ws As Worksheet
 Set ws = Sheets("Request")
 If ws.Range("C8[B][COLOR=#FF0000]").DisplayFormat[/COLOR][/B].Interior.Color = RGB(255, 0, 0) Then
 MsgBox "Duplicate class!"
 End If
 End Sub
 
Upvote 0
Just note that if you do it in a normal procedure like that, it won't happen automatically. You will need to manually call and run the code.
 
Upvote 0
Surely the conditional formatting itself is enough. Why the need for the message box? Isnt that the purpose of conditional formatting?
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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