two messages based on Conditional formated colours.

hurfy

New Member
Joined
Feb 28, 2019
Messages
4
hi everyone,

I have 7 cells in a column which are conditionally formatted. I'm trying to write some code based on any cells that are coloured vbRed or another message if none of them are.

I've copied most of the code from previous threads but I still cant get it to work, so any help would be greatly appreciated.:)
Code:
Sub test()
    Dim oneCell As Range, newNote As String


    For Each oneCell In Range("n17:n23")
        With oneCell
            If oneCell.DisplayFormat.Interior.Color = vbRed Then
                MsgBox ("please correct error from one or more cells being red")
                If newNote = "False" Then
                MsgBox ("all correct")
                    Exit For
                Else
                    .NoteText newNote
                End If
            End If
        End With
    Next oneCell
End Sub
 
Last edited by a moderator:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi & welcome to MrExcel.
How about
Code:
Sub hurfy()
   Dim Cl As Range
   Dim Flg As Boolean
   
   For Each Cl In Range("N17:N23")
      If Cl.DisplayFormat.Interior.Color = vbRed Then
         Flg = True
         Exit For
      End If
   Next Cl
   If Flg Then
      MsgBox "please correct error from one or more cells being red"
   Else
      MsgBox "All ok"
   End If
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
Code:
Sub hurfy()
   Dim Cl As Range
   Dim Flg As Boolean
   
   For Each Cl In Range("N17:N23")
      If Cl.DisplayFormat.Interior.Color = vbRed Then
         Flg = True
         Exit For
      End If
   Next Cl
   If Flg Then
      MsgBox "please correct error from one or more cells being red"
   Else
      MsgBox "All ok"
   End If
End Sub

thankyou so much Fluff, it worked perfectly. clearly I need more training. :)
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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