PDA

View Full Version : Solved: Relying on Exit Sub too much



doctortt
04-04-2011, 12:42 PM
I have codes to check a few cells for blank and space, and my sample codes are like this: (I have the actual working codes by the way)

For each box in range(blabalbahlbah)

If cell is empty, throw an error message: exit sub

If cell has a space, throw an error message: exit sub

Next box

Basically, if excel throws out an error message, I want to give the user an opportunity to re-enter the value and run the program again. But I think I'm relying too much on "exit sub." Is there a way to combine them?

Thanks

Bob Phillips
04-04-2011, 12:57 PM
For Each box In Range(blabalbahlbah)

If box.Value = "" Or box.Value = " " Then

If MsgBox("Cell " & box.Address & " is empty, do you want to load it?", vbYesNo) = vbYes Then

box.Value = Application.InputBox("Input into cell " & box.Address, Type:=3)
End If
End If
Next box

doctortt
04-05-2011, 03:10 PM
For Each box In Range(blabalbahlbah)

If box.Value = "" Or box.Value = " " Then

If MsgBox("Cell " & box.Address & " is empty, do you want to load it?", vbYesNo) = vbYes Then

box.Value = Application.InputBox("Input into cell " & box.Address, Type:=3)
End If
End If
Next box


One last thing, if the user click "No," What is your recommendation to make excel stop the program completely in the codes you posted?

Bob Phillips
04-05-2011, 03:19 PM
Else
Exit Sub

doctortt
04-05-2011, 03:22 PM
thanks big shot