+ Reply to Thread
Results 1 to 18 of 18

Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

  1. #1
    Forum Contributor
    Join Date
    07-19-2010
    Location
    Huddersfield, UK
    MS-Off Ver
    Excel 2007, 2010
    Posts
    167

    Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Morning all,

    I have several large codes which run reports that are all run through a user form. Each button calls a different proceedure. One of these proceedures opens up a raw data sheet and fills in some blank cells. If any cells can't be filled in it throws up a message box to alert the user that some data needs to be added manually.

    What I'm after is a message box to appear with this alert, and allow the user to either cancel the macro, edit the data necessary and re-run the macro from th beginnng (by clicking the user form button again), or 'suspend' the macro, make the edits, and click a button to continue the macro from where it left off.

    After doing a lot of hunting round, I've found I can't do this from a message box as it won't let you edit a worksheet while the message box is visible, and using a user form is the better way. I've created a second userform for this scenario - simple text with two buttons - Continue and Cancel.

    I can get the code to display this second userform when it finds any relevant cells, but what I'm struggling with is how to code the Continue button to jump back into the code within the first userform and resume from just after the form was called in the first place.....

    Below is the snippet of code I have already tried with the messagebox function. The user form I'm trying to call is called 'NoData', and all the code is contained within the first userform code module.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Hi,
    Some optins/ideas
    1) May be you can popup InputBox to fill values you need and after this is done - go on with existing code
    2) You could change existing code: move part of the code which is AFTER your data check to separate sub routine.
    Then check your data, if everything is OK - Call SeparateSub, if not - popup your MsgBox about lack of data and Exit Sub.
    After all data is corrected and you need to Continue - bind this SeparateSub to button Continue and rest of code will do what you need to finish.

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Use a Userform set modal to true and do your thing
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  4. #4
    Forum Contributor
    Join Date
    07-19-2010
    Location
    Huddersfield, UK
    MS-Off Ver
    Excel 2007, 2010
    Posts
    167

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    kasan - the input box wouldn't work due to the data that's required - mostly it's copied from somewhere else (more to prevent spelling errors), either another worksheet or from our system. Splitting the code out may work, but the macro in it's entirety is massive as it is - splitting out would mean finding and redefining all the variables I'm moving over. Can be done, just wondering if there's another way that doesn't involve re-writing half the code that works perfectly without this check. Also, if there is no errors and the 2nd form doesn't fire, then then macro will need to simply continue to the end. This part would be exactly the same as if the user had clicked 'Continue'. Seemed unfriendly to have the same code in two places.

    Keebellah - it's the 'do your thing' I'm struggling with, hence the question. I can get the userform to display and allow the user to edit the workbook(s) behind it, but don't know how to code in the button to get it to continue with the original code once they've finished editing.
    Last edited by dancing-shadow; 01-10-2017 at 06:56 AM.

  5. #5
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Keebellah's suggestion might work for you, I think.
    You CAN display userform and allow user to edit workbook. You need to set "ShowModal" property to False (Under UserForm properties).

  6. #6
    Forum Contributor
    Join Date
    07-19-2010
    Location
    Huddersfield, UK
    MS-Off Ver
    Excel 2007, 2010
    Posts
    167

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Yes but that's not the part I'm struggling with... I can get the userform to display and I can set it to modal so they can edit whatever they need. This I can do/have done. It's the part where they click continue to resume that I'm struggling with...

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    In the userform you will have to add extra button(s) that the user can press to trigger the following steps.
    The userform should be run from a separate macro that can process the rest of the code.
    Once the user finishes what he/she is doing he/she presses the (specific) button and maybe including a prompt to verify if the code has to be run do the next thing, the final step in all the code will be to Unload the userform from memory.
    I understand that a sample would help to show it and will tell more that all the explanations but attach a sample of a file you use (non-sensitive data) and what you want it to do and I'll see if I can put something together for you.

  8. #8
    Forum Contributor
    Join Date
    07-19-2010
    Location
    Huddersfield, UK
    MS-Off Ver
    Excel 2007, 2010
    Posts
    167

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    I can't create a sample due to the size/complexity of the whole file - creating the sample would take as long as it would to split the code out into several parts and duplicate it into the 2nd userform... The code I have above is triggered from the original button on UserForm1 (stored in code sheet for userform1), and manipulates data on a seperate file - 'mybook'. IF it finds any cells in col I that contain 'no data' it displays the message box (to be replaced by the userform). If none of these cells are found it simply completes the remainder of the macro (mainly saving the file as specific file names). If the messagebox/2nd userform is triggered, it does have two buttons in order to trigger the next steps - 'Continue' to resume the original macro, and 'Cancel' to exit the origional macro. All original macros are stored on the 1st userform code sheet/module.

    Sorry, I don't feel I'm able to explain this any better Best I can do is upload a flow chart of what I want if that would help.

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Okay, if you can provide a flow chart that will give me a better picture.
    Is it correct to assume that it all regards one worksheet only?

  10. #10
    Forum Contributor
    Join Date
    07-19-2010
    Location
    Huddersfield, UK
    MS-Off Ver
    Excel 2007, 2010
    Posts
    167

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Hope this helps...

    All the code is currently working so that if it encounters a blank/no data cell, it populates a message box and exits the macro. The code I posted above is what I initially tried before finding out that messagebox cannot be used in this scenario. I have the 2nd userform created (called 'NoData') which has the two buttons required, it's just coding the 'Continue' button part I need the help with

    If the macro always showed the 2nd userform every time, I could just split the code to continue on the 2nd userform code module. As this is in effect an error handler, it doesn't always show, and the macro needs to be able to run from start to finish with no userform/mesage box if it it doesn't encounter the cells specified. I can call a different Sub from within a Sub routine, and I can tell the process to 'Goto' a section which exists within the original code. I guess I'm trying to merge the two operations in a way, by telling the 2nd userform code to 'Goto' a section within the first userform Sub routine...


    I found this thread here - http://www.ozgrid.com/forum/showthread.php?t=150014 - which sounds like what I want to do, but not quite sure of the best way to set it up....
    Attached Files Attached Files
    Last edited by dancing-shadow; 01-10-2017 at 09:47 AM.

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    That's quite clear. let me take a look and see what I can do for you.
    I cannot promise to have it done right away but I have an idea.
    I'll work it out and let you know asap

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    My idea didn't work so I'm still at it.
    Had Internet connection problems so wasn't abe to do much between 19:00 and 22:00, will continue tomorrow.
    Cheers

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Okay, this a quick and dirty solution.
    I'll explain it tomorrow but maybe you can test it with this file
    Run the macro StartDataCheck to start it.
    Attached Files Attached Files

  14. #14
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Test this solution with UserForm.
    Main task is to copy values from column A to column C, but this can be done only if there are no empty cells in column A.
    Start from UserForm at the beginning, press Start button (CommandButton3) and code will check if there are any empty cells - if empty cell is found then execution of code is interrupted.
    After you correct data you can press Resume, but actually this will run the same CommandButton3_Click code, because you never know if all data was corrected- so we need to check it again, right?
    In case there are no empty cells then Main action will be processed and code will finish work. In case you will press Cancel button - UserForm will be unloaded and nothing will happen.
    All you need to do is to put your "check data" code into UserForm code, this part is not so "heavy" as I can see in your code from post #1

    Code for UserForm:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    My guess is that something went wrong and you did not see my file.
    I'm attaching it again.
    Run the first macro in Module1 to test

    PS The userform 'follows' the row to edit so it will be always displayed next to it
    Attached Files Attached Files
    Last edited by Keebellah; 01-12-2017 at 04:07 AM. Reason: added information

  16. #16
    Forum Contributor
    Join Date
    07-19-2010
    Location
    Huddersfield, UK
    MS-Off Ver
    Excel 2007, 2010
    Posts
    167

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Sorrt Keebellah, I have been off work for a while, hence not responding. I have had a play with your file (thank you for your time with this), but I don't think it'll work how I want, and keep the initial userform clear of potentially unnecessary extra buttons. Splitting/duplicating the code out into the 2nd userform may be the best way for this to work, although it's not ideal if I need to update the code in future, I'll have to ensure the changes are replicated for both forms.

    Thanks again for your time and help - feel I'll have to ditch the idea for now and may revisit it if/when the entire file gets a revamp.

  17. #17
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    No problem, you know where to find us.
    Happy coding

  18. #18
    Forum Contributor
    Join Date
    07-19-2010
    Location
    Huddersfield, UK
    MS-Off Ver
    Excel 2007, 2010
    Posts
    167

    Re: Show UserForm with Continue/Cancel buttons, allowing user to edit sheet

    Sorrt Keebellah, I have been off work for a while, hence not responding. I have had a play with your file (thank you for your time with this), but I don't think it'll work how I want, and keep the initial userform clear of potentially unnecessary extra buttons. Splitting/duplicating the code out into the 2nd userform may be the best way for this to work, although it's not ideal if I need to update the code in future, I'll have to ensure the changes are replicated for both forms.

    Thanks again for your time and help - feel I'll have to ditch the idea for now and may revisit it if/when the entire file gets a revamp.

+ 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. Userform Cancel edit that restores all original values?
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-18-2016, 11:36 AM
  2. [SOLVED] Allowing Multiple user to enter data from a sinlgle userform
    By rv02 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-24-2016, 04:46 AM
  3. Macro for allowing access for users to click buttons when sheet is protected
    By targus92 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2016, 12:29 PM
  4. Replies: 2
    Last Post: 08-18-2013, 12:23 PM
  5. [SOLVED] Can one use a Listbox on UserForm without allowing the user to select an item?
    By StevenM in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-26-2012, 05:44 PM
  6. Userform - Continue and cancel command buttons code
    By Jessica.Bush in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-01-2010, 04:42 PM
  7. Allowing user to select a cell but not edit it?
    By Falantar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-26-2009, 09:18 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