+ Reply to Thread
Results 1 to 10 of 10

Closing the InputBox when Cancel is selected

  1. #1
    Forum Contributor
    Join Date
    10-30-2014
    Location
    Pretoria, South Africa
    MS-Off Ver
    Office 365
    Posts
    111

    Closing the InputBox when Cancel is selected

    Good Morning,

    I hope you all are doing well.

    I was hoping that someone can perhaps show me how do I add code to exit the sub when the cancel button is selected on the InputBox. I have tried I few option on the forum, but do not seem to get it working. I am very new to vba and perhaps are missing the obvious.

    I am filtering a list of data populated in sheet3 to only show certain data entries based on date values. this is working fine, but when I hit cancel the code is still running as if I entered a "0" for the days.

    Your help would be highly appreciated.

    I thank you in advance.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Closing the InputBox when Cancel is selected

    One of these two:
    Please Login or Register  to view this content.

    OR


    Please Login or Register  to view this content.
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Forum Contributor
    Join Date
    10-30-2014
    Location
    Pretoria, South Africa
    MS-Off Ver
    Office 365
    Posts
    111

    Re: Closing the InputBox when Cancel is selected

    Hi there, thank for the prompt response.

    IsNumber - what should that be defined as?

    Thanks!

    Excel.png

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Closing the InputBox when Cancel is selected

    Sorry. It should be IsNumeric.

    There is VBA.IsNumeric which I wanted to use
    and WorksheetFunction.IsNumber which is the same as =IsNumber() used on worksheet.

    Just replace IsNumber with IsNumeric

  5. #5
    Forum Contributor
    Join Date
    10-30-2014
    Location
    Pretoria, South Africa
    MS-Off Ver
    Office 365
    Posts
    111

    Re: Closing the InputBox when Cancel is selected

    Hi there,

    Thanks bith of your methods run the code perfectly, excpet that I still have the same problem. If I add for example 0 in my search, the filtered data appears perfectly in my ListBox, but if I hit "cancel" it list all the entries in my ListBox from my worksheet. Sound like not something easy to fix hehe. Below is a few screen dumps of what I means. Excel1.pngExcel2.png

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Closing the InputBox when Cancel is selected

    OK, let me explain the code step by step, because maybe I don't get right what you want. From your initial post my understanding was that you want to properly handle the cancel click.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Closing the InputBox when Cancel is selected

    aha, I get it - you want to keep the current applied filter if Cancel click

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    10-30-2014
    Location
    Pretoria, South Africa
    MS-Off Ver
    Office 365
    Posts
    111

    Re: Closing the InputBox when Cancel is selected

    I think perhaps I am explaining like its already weekend or something hehe. Need a cold one.

    I think where I am going wrong is that the whole filtering and everything is already happening and populating.

    Basically all I want is, before anything happens, if I select the cancel button, my Listbox should remain empty, no entries. It should only populate information based on the number of days entered and if I enter a value and hit the "ok" button.

    I hope I make more sense .

  9. #9
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Closing the InputBox when Cancel is selected

    OK, here in this code you don't populate any listbox. You just filter some data on the worksheet. The code that populates (some) listbox is somewhere else in your code. It's also possible that your listbox is linked to sourcerange on the sheet... In any case - from this part of the code I cannot see what is going on with your listbox.
    Please provide full code. sample workbook, free of any sensitive data will be of great help

  10. #10
    Forum Contributor
    Join Date
    10-30-2014
    Location
    Pretoria, South Africa
    MS-Off Ver
    Office 365
    Posts
    111

    Re: Closing the InputBox when Cancel is selected

    Happiness!!!! Thanks buddy!!!!

    You asked the right questions and all I had to do was to insert your code before the the code related to my listbox that you were referring to above.

    I made the mistake in putting the code in a module and then call it in when I run a code from another command button.

    Thanks a million, much appreciated!!!!


+ 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] inputbox cancel
    By jacobsoo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-26-2013, 07:03 AM
  2. InputBox and Cancel
    By michaelaindia in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-24-2012, 04:32 AM
  3. [SOLVED] Cancel my Inputbox
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2012, 11:05 AM
  4. Cancel on Inputbox not work
    By unley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2011, 07:59 PM
  5. InputBox - Cancel
    By Lonwez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2005, 07:17 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