Error Message Box

  • Thread starter Thread starter alish
  • Start date Start date
A

alish

All,
How to me excel to give an error message on a conditional format?Like for
example if a cell is greater than 365 besides giving a red background as it
is conditional formatted, it also should shoot an error message in the screen
saying for instance "over 365 dyas" or something. Your help is appreciated.
Thanks.
 
CF cannot give you messages, only change formatting.

To have the message shown you would need a formula in an adjacent cell.

Assume A1 is to be red...........in B1 enter

=IF(A1>365,"A1 has exceeded 365 days")

Alternative would be to use VBA event code to pop up a message box and color at
the same time.

Private Sub Worksheet_Calculate()
On Error GoTo stoppit
Application.EnableEvents = False
With Me.Range("A1")
If .Value > 365 Then
..Interior.ColorIndex = 3
MsgBox "Please be advised that A1 has exceeded 365 days"
End If
End With
stoppit:
Application.EnableEvents = True
End Sub


This is sheet event code. Right-click on the sheet tab and "View Code".
Copy/paste the above into that sheet module.

Edit the range "A1" to suit.

Alt + q to return to the Excel window


Gord Dibben MS Excel MVP
 
Gord, Thanks, it worked!

Gord Dibben said:
CF cannot give you messages, only change formatting.

To have the message shown you would need a formula in an adjacent cell.

Assume A1 is to be red...........in B1 enter

=IF(A1>365,"A1 has exceeded 365 days")

Alternative would be to use VBA event code to pop up a message box and color at
the same time.

Private Sub Worksheet_Calculate()
On Error GoTo stoppit
Application.EnableEvents = False
With Me.Range("A1")
If .Value > 365 Then
..Interior.ColorIndex = 3
MsgBox "Please be advised that A1 has exceeded 365 days"
End If
End With
stoppit:
Application.EnableEvents = True
End Sub


This is sheet event code. Right-click on the sheet tab and "View Code".
Copy/paste the above into that sheet module.

Edit the range "A1" to suit.

Alt + q to return to the Excel window


Gord Dibben MS Excel MVP
 
Back
Top