+ Reply to Thread
Results 1 to 17 of 17

Macro deactivated in specific worksheet

  1. #1
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Macro deactivated in specific worksheet

    Hello,

    Would it be possible not to run a macro in specific worksheet?? I run a macro with the shortcut CTRL + P and I need to have that macro to be deactivated on certain worksheets (the worksheet names are "RENTCU1", "RENTCU2", "RENTCU3", "RENTCU4".

    Thanks,
    Graig

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Macro deactivated in specific worksheet

    put an activesheet.name check at the start of the macro.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Macro deactivated in specific worksheet

    Thanks but I need to have it work the other way around. I would like to specify the worksheets I do not want to macro to be run.

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

    Re: Macro deactivated in specific worksheet

    Does this macro run on multiple worksheets when you call it or only on the active sheet?
    If posting code please use code tags, see here.

  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: Macro deactivated in specific worksheet

    can you post your macro? it is hard to know how to help with the code if we don't know what we are helping on. Do you reference the worksheet in your macro? Does the macro loop through all sheets?
    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 Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Macro deactivated in specific worksheet

    Sure!

    My macro is that one:

    Please Login or Register  to view this content.
    The worksheets that I do not want that macro o be run are: "RENTCU1", "RENTCU2", "RENTCU3", "RENTCU4"

    Many Thanks in advance.
    Graig

  7. #7
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Macro deactivated in specific worksheet

    Sure!

    My macro is that one:

    Please Login or Register  to view this content.
    The worksheets that I do not want that macro o be run are: "RENTCU1", "RENTCU2", "RENTCU3", "RENTCU4"

    Many Thanks in advance.
    Graig

  8. #8
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Macro deactivated in specific worksheet

    Yes, thats what i was getting at, in the 1st line of macro have

    Please Login or Register  to view this content.

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro deactivated in specific worksheet

    Hi, graiggoriz,

    maybe add this to ThisWorkbook and see if it works as expected:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  10. #10
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Macro deactivated in specific worksheet

    Hello Holger,

    Are you saying that I need to *** that code in the 4 worksheets? (right click on the tab; view code. and add the code?

    If so, I already have the below code in each worksheet. If you meant to add the code differently can you please provide me the step? I don't know how to do that...

    Please Login or Register  to view this content.
    Many Thanks,
    Graig

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Macro deactivated in specific worksheet

    I think this will do what you want.
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  12. #12
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Macro deactivated in specific worksheet

    Hey mikerickson!! You got it!! Very good.

    I only have on problem with the printing part as if I cancel the printing I see the macro and in the file I use there is password! Would you know if the below macro can be enhanced and give me a pop up "would you like to print that document" and putting a condition that if "no" then it ends the macro instead of entering in debug mode! In the end I need to print that document as pdf but I did not know how to do that so I recorded a macro (CTRL + P)

    Do you think you could help me with that matter?


    Please Login or Register  to view this content.
    Many Thanks,
    Graig

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

    Re: Macro deactivated in specific worksheet

    graig, change it to:

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Macro deactivated in specific worksheet

    Hello,

    Thanks to all! I have compiled the macros and got that:

    Please Login or Register  to view this content.
    I have the following error:
    Compile error:
    Block If without End If

    Can you please help me fixing that error?

    Many thanks,
    Graig

  15. #15
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro deactivated in specific worksheet

    Hi, graiggoriz,

    indention could be one way to find the error, this is untested (I shifted some of the lines):
    Please Login or Register  to view this content.
    Ciao,
    Holger

  16. #16
    Forum Contributor
    Join Date
    02-21-2007
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    389

    Re: Macro deactivated in specific worksheet

    Hello,

    Thanks to all! I have compiled the macros and got that:

    Please Login or Register  to view this content.
    I have the following error:
    Compile error:
    Block If without End If

    Can you please help me fixing that error?

    Many thanks,
    Graig

  17. #17
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro deactivated in specific worksheet

    Hi, Graig,

    I don´t get the reason for repeating the post from 08:50 PM at 10:15 PM (I know there have been Forum issues and my post wasn´t properly displayed nor passed to my count nor was displayed on the survey of the Forum). Did you try my suggestion?

    Ciao,
    Holger

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

    Re: Macro deactivated in specific worksheet

    your 'print version section has an if, no end if. The end if near the bottom applies to "if not" at the top. I suggest adding an "End If" just before "End Sub"

+ 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. Copying specific data to a specific field in a worksheet macro
    By bradpeh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2013, 01:52 AM
  2. [SOLVED] Delete worksheet if it is deactivated?
    By Alexander_Golinsky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2013, 01:54 AM
  3. Macro to pull specific data from one worksheet to another worksheet
    By Kettie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2013, 05:21 PM
  4. Code adjustment needed-warning message and highlighting is deactivated.
    By baffled1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-01-2011, 09:23 PM
  5. Worksheet_Deactivate procedure leaves me on the deactivated sheet
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2008, 05:21 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