PDA

View Full Version : [SOLVED] Exit sub as InputBox is cancelled



Olwa
06-29-2017, 11:36 PM
Hi there,
i want to delete a row (lindex) and exit sub as the user cancels the inputbox. Tried different versions like the following, but nothing seemed to work. Any suggestions?


text = Application.InputBox("Do something!")
If StrPtr(text) = 0 Then
Rows(lIndex).EntireRow.Delete
Exit Sub
End If


text = Application.InputBox("Do something!")
If text = 0 Then
Rows(lIndex).EntireRow.Delete
Exit Sub
End If


text = Application.InputBox("Do something!")
If text = "" Then
Rows(lIndex).EntireRow.Delete
Exit Sub
End If


text = Application.InputBox("Do something!")
If text = vbNullString Then
Rows(lIndex).EntireRow.Delete
Exit Sub
End If

Olwa
06-30-2017, 12:44 AM
Nevermind, found a solution "finally"! :)


If text = False Then
Rows(lIndex).EntireRow.Delete
Exit Sub
End If

mdmackillop
06-30-2017, 04:16 AM
If nothing is entered and you OK or you Cancel, you'll get different values for Text. To cover both

If Text = False Or Text = "" Then

Put Breaks on Exit Sub and End Sub lines and watch the Text value

Is there a reason for using Application.Inputbox (http://www.wiseowl.co.uk/blog/s2458/inputbox.htm)?

Olwa
06-30-2017, 05:19 AM
Ye, might be useful to "block" Text = "" too, thanks for the hint.
There might be a reason to use an application inputbox, as im pretty sure that the value is always going to be a number. Not 100% sure yet, so im just using it like that right now during the development.