+ Reply to Thread
Results 1 to 3 of 3

InputBox- Amend 'Cancel' Button

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-09-2015
    Location
    malta
    MS-Off Ver
    Microsoft 365
    Posts
    387

    InputBox- Amend 'Cancel' Button

    Hi guys,

    If it is not too much to ask can someone help me out with the below.

    Basically I have this macro which every time it is run an input box will pop up and:
    -if a 1 is inserted it will call a macro called January
    -if a 2 is inserted it will call a macro called February


    Sub Monthly_Report_viewer()
    
    vervolg:
          r = InputBox("Type the Month you would like to view" _
            & Chr(13) & Chr(13) & "e.g:1 for January", "Monthly Report")
            
            If r = 1 Then
                Call January
                Exit Sub
            End If
            
            If r = 2 Then
                Call February
                Exit Sub
            End If
    
      GoTo vervolg
            
    End Sub
    Now, the input box also has a 'Cancel' button. Would it be possible to amend the code so as to close the input box if someone clicks the 'Cancel' button?

    Appreciate a lot your kind help!!

    Thanks

    Keibri

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: InputBox- Amend 'Cancel' Button

    Keibri

    Try this.
    Sub Monthly_Report_viewer()
    Dim r As Variant
    
    vervolg:
        r = InputBox("Type the Month you would like to view" _
                     & Chr(13) & Chr(13) & "e.g:1 for January", "Monthly Report")
    
        If r = "" Then Exit Sub
        
        If r = 1 Then
            'Call January
            Exit Sub
        End If
    
        If r = 2 Then
            'Call February
            Exit Sub
        End If
    
        GoTo vervolg
    
    End Sub
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    02-09-2015
    Location
    malta
    MS-Off Ver
    Microsoft 365
    Posts
    387

    Re: InputBox- Amend 'Cancel' Button

    Thanks Norie!! That was great and worked wonders. Cheers for your great help!

+ 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] Exit Sub if Inputbox cancel, X Button or blank value is used (bypass debug)
    By liamtimms1985 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2015, 07:03 AM
  2. InputBox OK and Cancel Button Problem
    By mackypogi in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-26-2014, 07:51 PM
  3. cancel button Application.Inputbox
    By TimlmiT in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-20-2014, 02:30 PM
  4. [SOLVED] Insert function to 'Cancel' Button in InputBox
    By leleco in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-16-2014, 11:52 AM
  5. add cancel button to inputbox
    By SarahPintal in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2011, 02:27 AM
  6. Inputbox cancel button error.
    By abhay_547 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-05-2010, 06:27 AM
  7. activate cancel button in a inputbox
    By mania112 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-19-2009, 07:09 AM

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