Results 1 to 40 of 40

Looping an Excel Inputbox with Single Range

Threaded View

  1. #1
    Registered User
    Join Date
    11-14-2022
    Location
    England
    MS-Off Ver
    MS365 (PC) Version 2308
    Posts
    59

    Question Looping an Excel Inputbox with Single Range

    Hello my potential saviour,

    I have been driven to despair with what I thought would be a simple VBA loop but after countless hours and many different searches I'm at a loss so have turned to you to ask for help.

    Although I have found similar people with my issue, none of them have the exact same problems, so I thought I'd start a new topic and lay out the steps of what I'm after in the hope someone can assist me.

    Point 1. I am trying to use an application.inputbox to ask the user to select a single range
    Point 2. If the user presses 'Cancel' on the inputbox screen then a msgbox should display "Macro Cancelled" and the macro is ended.
    Point 3. If the user presses 'Ok' when the inputbox is blank or the user selects a cell without a formula in then a msgbox should display "No formula in the selected cell. Please select a cell with a formula." and the macro is looped.

    Note: If the user sees the message from Point 3 and loops back, pressing 'Cancel' now should still react like Point 2. (In my current code it just creates an endless loop - See below for more details)
    Likewise if the user doesn't input anything into the inputbox and presses 'Ok' then the default excel message shouldn't pop up because I would like the msgbox from point 3 to show instead.

    I have attached a sample workbook where range A1 contains a formula, Range A2 contains a value and all other cells are empty.
    The code I currently have works if the user presses 'Cancel' before attempting to select a range, however if the user selects a range that doesn't contain a formula they get caught in an endless loop even if they press 'Cancel'. Also my code doesn't handle if a user leaves the inputbox blank and presses 'Ok'

    This part of the code is part of a larger macro which actually asks a user for a 2nd input and then compares the run times of the two formulas. However I don't think that is needed so I have simplified the problem for now and hope to be able to scale it up.

    Thank you in advance and I'll be around if you have any further questions or need any extra info.
    EricDonk
    Attached Files Attached Files
    Last edited by EricDonk; 07-11-2024 at 04:03 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 05-07-2020, 12:17 AM
  2. VBA inputbox error - looping problem
    By dmihaljevic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-05-2014, 09:07 AM
  3. Inputbox to retrieve Excel range from Powerpoint VBA
    By submariner18 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2013, 01:50 AM
  4. [SOLVED] InputBox option and its features(looping,row switching,data collecting)
    By 4evra in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-29-2013, 02:05 PM
  5. [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
  6. [SOLVED] Trouble Looping Through an Excel Range using a 2D 'For Loop' with VBA
    By Sarvazad in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-14-2013, 04:33 PM
  7. looping through a range of cells in excel
    By rbhandair in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2007, 09:19 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