+ Reply to Thread
Results 1 to 30 of 30

Run multiple macros depending on checkboxes

  1. #1
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Run multiple macros depending on checkboxes

    Im looking to run multiple macros, not just one. How do I change this code to do that?
    This code works but only runs one macro. I want to run multiple.

    Please Login or Register  to view this content.
    Any help here is progress. Thanks

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Run multiple macros depending on checkboxes

    Hi,

    What you mean is that, when the user selects 2 check boxes you need to run 2 procedures (macros).
    Basically the user can select multiple check boxes , am i clear with what you need ?
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Run multiple macros depending on checkboxes

    Hi, you could try something lik this
    Havent tested the code as i dont have time at the moment, but might help you start

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  5. #5
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    @ xlbiznes yes, That is what im looking for.

    @ Norie, i get a "runtime error 424, Object required" that i had received before and i do believe its because of the "zlOn Then" code. not quite sure though. I have tried the If Then clause but i havent been able to get it to work.

    @ Sean I get the same thing with yours also Sean,
    going to keep testing and tweeking
    Last edited by krackaberr; 02-25-2013 at 10:26 AM.

  6. #6
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Run multiple macros depending on checkboxes

    Hi,

    You can simply loop through your existing code 15 times (Based on your code i could see 15 check boxes).

    Please find the code below , basically its your code with my additional lines of code.


    Please Login or Register  to view this content.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run multiple macros depending on checkboxes

    krackaberr

    Where do you get the error?

  8. #8
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    Please Login or Register  to view this content.

    @ xlbiznes is the loop going to re-run macros it has already run? seems like I need to clear the last Checkbox run before end of each loop
    Last edited by krackaberr; 02-25-2013 at 10:36 AM.

  9. #9
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    "Runtime code 424 Object Required"

    @ xlbiznes
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    I have found that running macros with checkboxes is very picky.... i like c++.... maybe thats kinda why i get confused quickly.

  11. #11
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Run multiple macros depending on checkboxes

    You are absolutely right. I missed that completely.

    Here you go.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    @ xlbiznes now im getting the same error on a different line.

    Please Login or Register  to view this content.

  13. #13
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Run multiple macros depending on checkboxes

    krackaberr,

    this would happen , only if the check box control is not present on the sheet.

    Run your initial code and see what happens.

  14. #14
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    now i do believe that any code that compares(case=comparison), is going to come back with run time errors. are there other codes that do the same statement?

    Inital code works fine....

    stepping into the code, it looks at the value of the check box, runs macro, then stops at that line with runtime error
    Last edited by krackaberr; 02-25-2013 at 10:56 AM.

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run multiple macros depending on checkboxes

    krackaberr

    Can you check that there is a checkbox with the name 'Checkbox 12' on the active sheet?

    Also, do any of the subs you are calling select/activate other sheets?

    If they do then ActiveSheet might not be referring to the correct worksheet.

    In fact why not change ActiveSheet to Worksheets("TheNameOfTheWorksheetWithTheCheckboxesOnIt")?

  16. #16
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    yes you are correct, i have to have it go to the main sheet again... adjusting code now...

  17. #17
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    xlbiznes,

    it didnt seem to like the worksheets("") code, so i went with this instead... some tweeking is needed but it seems to work.


    Please Login or Register  to view this content.

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run multiple macros depending on checkboxes

    Did you try adding an explicit worksheet reference instead of just ActiveSheet like I suggested?

    Like this, which worked for me.
    Please Login or Register  to view this content.
    Last edited by Norie; 02-25-2013 at 11:31 AM.

  19. #19
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    i tried yes, but when i debugged, it wanted an end of line instead of check box...

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run multiple macros depending on checkboxes

    Have a look at the code I added and the attached file.
    Attached Files Attached Files
    Last edited by Norie; 02-25-2013 at 11:50 AM.

  21. #21
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    I tried the code... assigned it, nothing happened... i mean nothing.
    it seems like the case statement works. not the if then statement.

    @ xlbiznes how do i add a msg box where if nothing is checked it pops up no checkbox selected, and if there was one selected it runs macro and then pops up message Macro/s Completed?

  22. #22
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    I didnt have this part of the code in the main tab code.
    This does work too....
    For my application, i would need to clear all the check boxes at the end of the code, looking into this now. then message boxes after that.
    Please Login or Register  to view this content.
    Last edited by krackaberr; 02-25-2013 at 12:06 PM.

  23. #23
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run multiple macros depending on checkboxes

    I just used that code to generate the checkboxes for testing, you can ignore it.

    If you want messages try this.
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    To reset the checkboxes, i used the
    Please Login or Register  to view this content.
    in another sub and called that at the end of the inital sub. just to make it look clean.

    Messages, i couldnt figure out how to declare variables, for my life, as the names are different from c,c++. im not multi-lingual as far as programming goes. same ideas but different words. ugh.

    Thanks to the both of you for all your input. both versions do work, but the case statement i think is harder to tweek as far as adding into the code. maybe just me though

  25. #25
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run multiple macros depending on checkboxes

    Select Case is desgined to only run the case that's true, it's not designed to run multiple cases.

    PS Doesn't C++, C use int (Integer) and long (Long)?

  26. #26
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    when vb uses if then clauses, does it run the then clause until it sees else of end if or can i use nested if thens?
    if that be the case can i add a statement in case of that macro not being able to point to a tab(tab does not exist) in certain cases?

    yes int but long not really, it uses double more. its the same a long or floating point.
    Last edited by krackaberr; 02-25-2013 at 01:07 PM.

  27. #27
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run multiple macros depending on checkboxes

    You can use nested Ifs but I don't quite see how that would help when a sheet doesn't exist.

  28. #28
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    i would be using if statements in my macro subs...
    i was thinking of this...
    Please Login or Register  to view this content.
    but im not sure yet how im going to use it yet.

    thinking

    On error resume next
    worksheetexists = (sheets(WorksheetName).Name <> "Project Info")
    if worksheetexists = true then
    macro
    else
    next
    Last edited by krackaberr; 02-25-2013 at 01:24 PM.

  29. #29
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Run multiple macros depending on checkboxes

    If this is about the subs perhaps you should start a new thread.

  30. #30
    Registered User
    Join Date
    01-31-2013
    Location
    Wisconsin USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Run multiple macros depending on checkboxes

    Quote Originally Posted by Norie View Post
    If this is about the subs perhaps you should start a new thread.
    agreed thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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