+ Reply to Thread
Results 1 to 4 of 4

Input box - cancel button

Hybrid View

jsherwood Input box - cancel button 10-05-2018, 02:48 PM
¯\\_(ツ)_/¯ Re: Input box - cancel button 10-05-2018, 02:59 PM
jsherwood Re: Input box - cancel button 10-05-2018, 03:41 PM
¯\\_(ツ)_/¯ Re: Input box - cancel button 10-05-2018, 04:11 PM
  1. #1
    Registered User
    Join Date
    09-16-2018
    Location
    Washington State, USA
    MS-Off Ver
    2016
    Posts
    43

    Input box - cancel button

    Hello All,

    I need some help writing a few lines that exits the sub if the users clicks the cancel button...........tried and am failing miserably!

    Sub SelectData()
        Dim s_row As Integer
        s_row = 14
        s_row = InputBox("ENTER ROW NUMBER FOR THE JOB YOU WERE AWARDED", "CREATE ACTIVE JOB")
          
        Sheets("ACTIVE JOBS").Unprotect "123"
        
        Set rng = Sheets("ACTIVE JOBS").Range("A6:R6")
        rng.Copy
        rng.EntireRow.Insert Shift:=xlDown
        Application.CutCopyMode = False
        
        Sheets("SALES PIPELINE").Range("A" & s_row & ":B" & s_row).Copy _
                    Destination:=Sheets("ACTIVE JOBS").Range("A7:B7")
      
        
        With Sheets("ACTIVE JOBS")
            .Protect "123"
            .EnableSelection = xlUnlockedCells
        End With
        
            
    End Sub

  2. #2
    Forum Contributor
    Join Date
    09-19-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    208

    Re: Input box - cancel button

    Try changing the variable s_row to String, then add one line of code as shown below:
    Dim s_row as String
    
    s_row = 14
    s_row = InputBox("ENTER ROW NUMBER FOR THE JOB YOU WERE AWARDED", "CREATE ACTIVE JOB")
    If s_row = vbNullString Then Exit Sub
    You may also want to add a check to confirm the string entered is a valid number (when converted from string to number), otherwise the remaining code may fail.

  3. #3
    Registered User
    Join Date
    09-16-2018
    Location
    Washington State, USA
    MS-Off Ver
    2016
    Posts
    43

    Re: Input box - cancel button

    That worked perfect! I agree with you about validating the other data. The user needs to select data within a specified table, how could I achieve that?

  4. #4
    Forum Contributor
    Join Date
    09-19-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    208

    Re: Input box - cancel button

    Something like this will check a range of cells to see if the value exists. If it does, you can proceed with your code in the Else portion of the IF statement.
    Dim s_row As String
    
    s_row = 14
    s_row = InputBox("ENTER ROW NUMBER FOR THE JOB YOU WERE AWARDED", "CREATE ACTIVE JOB")
    If s_row = vbNullString Then Exit Sub
    If IsError(Application.Match(s_row, Sheets("Sheet1").Range("A1:A20"), 0)) Then
        MsgBox "You must enter a valid value that exists in Sheet1!A1:A20.", vbOKOnly, "Invalid Entry"
    Else
        ' Do your stuff
    End If

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Problem with my cancel button on my input box
    By danbates in forum Excel General
    Replies: 7
    Last Post: 01-23-2017, 06:35 AM
  2. [SOLVED] Input Box Cancel Button
    By underwater24 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-26-2016, 05:08 PM
  3. [SOLVED] Problem with CANCEL button, INPUT BOX
    By GIS2013 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-18-2014, 04:26 PM
  4. [SOLVED] Input box and the cancel button
    By Saturn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2014, 01:21 PM
  5. [SOLVED] Input Box must be integer, Cancel button type mismatch
    By Nrowell92 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-30-2012, 03:29 PM
  6. Cancelling an inputbox if blank input or cancel button is pressed
    By kathhying in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2011, 12:07 PM
  7. Cancel button on input box causes crash
    By EGR2317 in forum Excel General
    Replies: 8
    Last Post: 06-04-2010, 09:51 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1