VB script for error text box

Closed
Kryton1976 - Jan 14, 2010 at 08:06 AM
tompols Posts 1273 Registration date Wednesday July 28, 2004 Status Contributor Last seen November 25, 2013 - Jan 14, 2010 at 12:29 PM
Hello,
Can some one please help before my head explodes. I need a script to look at a range and if the cell contains a "0" then flash up a warning box. I can get it to work for one cell with the syntax below but cannot get it to work for a range of cells. I am a complete novice.

Thanks

2 responses

Sorry,

Syntax for one cell i have is

Private Sub Worksheet_Calculate()
If Range("g24").Value < 1 Then MsgBox "No cover for this shift?!!", 48, "Warning...Warning..."

End Sub
but i want to look at the range g24-gh24

TVM
0
tompols Posts 1273 Registration date Wednesday July 28, 2004 Status Contributor Last seen November 25, 2013 28
Jan 14, 2010 at 12:29 PM
Hello,
try this, just adapt the Range("G24:H24") if needed ;)
Private Sub Worksheet_Calculate()

Dim cpt As Integer
cpt = 0 'used to count "0" values as you don't want to display 2 messages if both cells are 0s....

For Each c In Range("G24:H24")
    If c.Value = 0 Then cpt = cpt + 1 
Next c

If cpt > 0 Then MsgBox "No cover for this shift?!!", 48, "Warning...Warning..."

End Sub
0