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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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