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
Bookmarks