+ Reply to Thread
Results 1 to 13 of 13

VBA runs on all active sheets and I only want it to run on 1 specific sheet

  1. #1
    Registered User
    Join Date
    02-26-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    42

    VBA runs on all active sheets and I only want it to run on 1 specific sheet

    I know this is probably an easy solve and I'm over looking something.
    I have a timer that starts once I load data from a source and I need it to stay running for when specific events happen I want the user to record the time. And found this timer works well as it sits on the sheet they need to enter the data in to and it's in sync with the network. So I have an accurate time capture.

    Problem with my code below.. It is active on ALL sheets. I have two sheets in this file.. but If they open up ANY other workbook it populates the time in cell A9.
    Can I define the clock to only appear on one specific sheet only like "Sheet 1"?
    Much thanks.


    Please Login or Register  to view this content.
    Last edited by Doolski; 05-12-2017 at 01:56 PM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet


    Do you know there is only one active sheet ?!

    Last edited by Marc L; 05-12-2017 at 02:03 PM. Reason: OP adds code tags …

  3. #3
    Registered User
    Join Date
    02-26-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    42

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    Sorry My apologies. Thread has been edited.

    I do know there is only one active sheet.. but when I click a new tab or open a new workbook it is now the active sheet and the VBA is applied to that new active sheet.

    Thx

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet


    So instead of ActiveSheet in code just use a valid reference to the desired worksheet …

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    I think the OP meant ANY active sheet, not "ALL"... yes best way is to specify the sheet instead of using active... the other way is If ActiveSheet.Name = "the sheet you want" then....
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    I think the OP meant ANY active sheet, not "ALL"... yes best way is to specify the sheet instead of using active... the other way is If ActiveSheet.Name = "the sheet you want" then....
    I guess it depends a little on what you want... no matter which sheet is active, you want to put the time in a specific sheet then use specific sheet. If you only want to execute the code if that specific sheet is active, then use an if statement to control when the code runs.

  7. #7
    Registered User
    Join Date
    02-26-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    42

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    Thanks for troubleshooting. I think it's a problem with the code...
    I define the sheet as you indicated but then I get errors as soon as I click on another tab and/or open a new workbook.

    So it must be re-running itself on each sheet and/or new workbook as it's trying to re-use the sheet name.

    01.jpg

    and this is the line error

    02.jpg

  8. #8
    Registered User
    Join Date
    02-26-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    42

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    I found out that when I stop the timer using this code"

    Please Login or Register  to view this content.
    It does not re-create the error but the clock stops running.

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    ActiveSheet.Name = ... sets the name...
    If what you want is (no matter which sheet is active), just put the time in that specific worksheet then :

    Please Login or Register  to view this content.
    If for some reason you need to activate that sheet (which is not what one should usually do just to put values, but only when truly needed): "Worksheets("Flt Watch Desk").Activate"

  10. #10
    Registered User
    Join Date
    02-26-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    42

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    So that may explain part of the coding issue.

    I defined the Worksheet can now run the code

    Please Login or Register  to view this content.
    and start a new sheet and the code won't run on the new sheet. This is good!

    But when I open a new workbook while I have this one running I get an error.

    1.jpg

    Do I need to define the workbook as well?
    Thx

  11. #11
    Registered User
    Join Date
    02-26-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    42

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    Here is the code I'm now using and the file.

    Please Login or Register  to view this content.
    When I open the workbook and click the box to run the macro. One the time populates and runs in 9, 1 then I open a new workbook.. error.
    Thx
    Attached Files Attached Files

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    try changing:

    Please Login or Register  to view this content.
    to:

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    02-26-2016
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    42

    Re: VBA runs on all active sheets and I only want it to run on 1 specific sheet

    Thanks Arkadi!
    This code works and solves the problem for this specific workbook. I had used this code in my working workbook with much more code and VBA. This works perfect so it tells me that my code in my other workbook is the problem.

    A new thread!
    Thanks for supporting this issue!

+ 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: 10-29-2014, 06:00 AM
  2. Application.onkey, only active on specific sheets!
    By ThomasAnthony in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2014, 12:13 PM
  3. Replies: 1
    Last Post: 01-04-2014, 06:37 PM
  4. [SOLVED] Macro only runs on specific sheet name
    By cymraeg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2013, 03:43 PM
  5. Macro stores Active Sheet range but I need it to find a new range each time it runs
    By jaroesner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2013, 08:00 AM
  6. Copy the data in any active row in Sheet 1 to specific cells in Sheet 6
    By cti4sw in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-04-2013, 02:43 PM
  7. [SOLVED] How to get (range)macro to always run code on a specific sheet regardless of active sheet?
    By JTwrk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2012, 04:33 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