Consulting

Results 1 to 4 of 4

Thread: Exit sub as InputBox is cancelled

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    26
    Location

    Exit sub as InputBox is cancelled

    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

  2. #2
    VBAX Regular
    Joined
    May 2017
    Posts
    26
    Location
    Nevermind, found a solution "finally"!

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

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Regular
    Joined
    May 2017
    Posts
    26
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •