+ Reply to Thread
Results 1 to 7 of 7

Repeat Inputbox if user click cancel or if user enter character not in selection criteria

  1. #1
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Repeat Inputbox if user click cancel or if user enter character not in selection criteria

    Hi,

    Can anyone help me on this problem.

    I need to repeat the input if user click cancel or enter value not it selection criteria. Here is my VBA code but got error

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Repeat Inputbox if user click cancel or if user enter character not in selection crite

    If by cancel button you mean the X on the top right hand of the form window I would just disable it with the code below and remove your 3rd if statement group from your code.

    Place this in the userform vba window:

    Please Login or Register  to view this content.

    Also note if you haven't already in some other portion of your coding will need an option for it to close on successful form completion.
    Last edited by playaller; 05-23-2014 at 03:38 PM. Reason: Advised of closing form after compeltion


    Shelton A.
    If Helpful, Add Reputaion!

  3. #3
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Repeat Inputbox if user click cancel or if user enter character not in selection crite

    Hi playaller,

    It means for both, (X) on the top right of the windows and also Cancel button in input box.

    If user click either one or both, Application.Inputbox will appear until the user key in correct character.

    If let say, the application request to input String (Y/N) but user enter number or symbols, the application still repeating until the correct character entered.


    Regards,
    Farid

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Repeat Inputbox if user click cancel or if user enter character not in selection crite

    A message box with two buttons would be a smother user interface
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Repeat Inputbox if user click cancel or if user enter character not in selection crite

    Hi mikerickson,

    Thanks for assist me.

    It is much easier than Application.Inputbox.


    Just to ask you what went wrong on my VBA code on the # post 1


    Regards,
    Farid

  6. #6
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: Repeat Inputbox if user click cancel or if user enter character not in selection crite

    If you had to use your code you could have tried to leave the last condition open since it would default if the other 2 didn't happen anyways so you would exit the sub but not end it leaving the window open after the message box. As is it would just loop to the message box if the first to conditions were not met. If it still errord we would need to know which line gives the erorr.



    sub data()
    Dim NewStaff As Boolean

    NewStaff = Application.InputBox("Is there any new staff to be updated?" & vbCrLf & vbCrLf & "Press Y, (Yes)" & vbCrLf & "Press N, (No)")

    If NewStaff = "Y" Or NewStaff = "y" Then

    Call XXXXXXXXX

    ElseIf NewStaff = "N" Or NewStaff = "n" Then

    Workbooks("workbookname").Close

    ElseIf NewStaff = "" Then

    MsgBox ("Please do not press cancel")
    Exit Sub
    End If

    end sub
    Last edited by playaller; 05-24-2014 at 02:12 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    696

    Re: Repeat Inputbox if user click cancel or if user enter character not in selection crite

    Hi Playller,

    Finally done. It works perfect.

    Anyway, thanks a lot.

    Please Login or Register  to view this content.

+ 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. Cell Selection based on user click
    By mohsinismail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2014, 12:28 PM
  2. [SOLVED] How to enable user to click "cancel" if file name exists when saving as...
    By TBO in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2014, 02:22 PM
  3. [SOLVED] Looping sub not detecting user cancel from inputbox
    By jshaw82 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2013, 06:14 PM
  4. Detect if user hits cancel from user input type box
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-20-2011, 11:42 AM
  5. Cancel Macro is user selects 'cancel' at save menu
    By Mark in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2005, 01:06 PM

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