VB script for error text box

Closed
Report
-
Posts
1219
Registration date
Wednesday July 28, 2004
Status
Contributor
Last seen
November 25, 2013
-
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 replies

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
Posts
1219
Registration date
Wednesday July 28, 2004
Status
Contributor
Last seen
November 25, 2013
28
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