+ Reply to Thread
Results 1 to 12 of 12

Change VBA Code so that it work on All Sheets and not only on Active Sheet.

  1. #1
    Registered User
    Join Date
    02-20-2014
    Location
    Romania
    MS-Off Ver
    Office 2016
    Posts
    28

    Smile Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    I am a noob as far as VBA is concerned. I was helped on this forum with the code below. What I want is to uncheck a Form Check Box automatically on the 28th of the month. The code below works well when I reopen the file but only when the sheet with the CheckBoxes is open at the moment of the opening of the file. If it is not active there's an error with debugging and stuff that I don't get. Is there any way to get it to work regardless of the sheet being active? In all the workbook. I have many sheets with hundreds of Checkboxes. Also I hope that the number assigned to the boxes doesn't repeat with others as it would cause trouble. Thanks.

    Please Login or Register  to view this content.
    Last edited by Chypp; 12-28-2017 at 10:03 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,859

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Last edited by AliGW; 12-28-2017 at 10:07 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    02-20-2014
    Location
    Romania
    MS-Off Ver
    Office 2016
    Posts
    28

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    Thanks.
    I solved it.
    Last edited by AliGW; 12-28-2017 at 10:06 AM. Reason: Unnecessary quotation removed.

  4. #4
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    Do you want to uncheck all checkboxes in the workbook or just certain ones?
    Design everything to be as simple as possible, but no simpler.

  5. #5
    Registered User
    Join Date
    02-20-2014
    Location
    Romania
    MS-Off Ver
    Office 2016
    Posts
    28

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    Only certain ones. That's why there was the Number of the CheckBox in the code. But I would like the code to work even when, upon opening of the file, the active sheet is not one of the ones with the Checkboxes. As the code is now, it only works when the sheet's active.

  6. #6
    Registered User
    Join Date
    12-28-2017
    Location
    Spain
    MS-Off Ver
    2013
    Posts
    5

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    Hi Chypp,

    You can introduce the sheet activation procedure into at the beginning of your code, so you can be working in other sheet and run your macro in the good one. You can use something like this:
    Please Login or Register  to view this content.
    Last edited by CO92; 12-28-2017 at 10:20 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    One last question: is it just one sheet that you would like to clear checkboxes on?
    If so, CO92's code above will work, like this:
    Please Login or Register  to view this content.
    If there are multiple sheets you wish to do then it will be a bit more complicated than the above

  8. #8
    Registered User
    Join Date
    02-20-2014
    Location
    Romania
    MS-Off Ver
    Office 2016
    Posts
    28

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    Thanks a lot, Stormin' and CO92! Using your suggestions I have managed to adapt a code where the sheets are activated and the unchecking is done alternatively for the Sheets that contain Checkboxes. They work perfectly. Thanks!

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    For people searching for a solution, like you did, would you mind showing your solution?

  10. #10
    Registered User
    Join Date
    02-20-2014
    Location
    Romania
    MS-Off Ver
    Office 2016
    Posts
    28

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    Sure. The solution is very specific to my needs but here it is:
    Basically, I needed Excel to automatically uncheck some (not all) of my Form CheckBoxes at the Beginning of the month so that some formulas could trigger Conditional Formatting on a different sheet. The problem was that the code that I had only worked for the active sheet at the moment of opening of the file. With the code below, the good people on this forum helped me consecutively activate the sheets containing the Boxes I needed unchecked before the code did the trick and then return to my overview sheet without causing errors. In case I don't close the file on the 1st of the month, the code below repeats every time I open the file from the 1st to the 3rd of the month. It works well.

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,527

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    Thank you Chypp.
    I am sure that it is very much appreciated by the people looking for a solution with the same or similar problem
    A belated Merry Christmas and a Happy and Prosperous New Year to you and yours.

  12. #12
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Change VBA Code so that it work on All Sheets and not only on Active Sheet.

    Thanks for posting your solution. You can also shorten the criteria for calling uncheck (and change it more easily).

    Please Login or Register  to view this content.
    So uncheck will be called if the day of the month is greater than or equal to 28, or less than or equal to 3 e.g. 28th Dec to 3rd Jan.

+ 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. Replies: 6
    Last Post: 11-29-2017, 03:00 AM
  2. [SOLVED] Setting Print area with VBA code on active sheet - Can't get my code to work
    By hans302 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2017, 05:07 AM
  3. vba code to update all pivot tables based on cell change on active sheet only
    By seatejo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-08-2014, 08:34 PM
  4. [SOLVED] How to change code so that it works in all active sheets
    By ciapul12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-18-2013, 10:38 PM
  5. [SOLVED] Why wont my search function work when i change it from all sheets to active sheet?
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2012, 12:58 PM
  6. [SOLVED] How to get Range Cells code to work on the non-active sheet
    By skysurfer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-02-2012, 07:13 PM
  7. change code to work over multiple sheets
    By cda_cmd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-14-2006, 09:10 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