+ Reply to Thread
Results 1 to 8 of 8

Toggle Macro On/Off

  1. #1
    Registered User
    Join Date
    11-08-2019
    Location
    Oregon
    MS-Off Ver
    Office 365
    Posts
    30

    Toggle Macro On/Off

    I use the following macro to fill cell C2 with the active cell value. Is there a way to toggle this on/off with a hotkey or other macro? It's tedious to open VB, delete the code, then re-enter it.

    Please Login or Register  to view this content.

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

    Arrow Re: Toggle Macro On/Off


    One way is to deactivate any event via the EnableEvents property …

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,481

    Re: Toggle Macro On/Off

    Add this line of code at the top of the code module that your posted code is in (this line of code should be by itself, that is, NOT inside of any code procedures)...

    Please Login or Register  to view this content.
    and put the following code in the same module, but it location is not critical...

    Please Login or Register  to view this content.
    Now, double clicking the C2 cell will toggle whether cell C2 updates or not.

  4. #4
    Registered User
    Join Date
    11-08-2019
    Location
    Oregon
    MS-Off Ver
    Office 365
    Posts
    30

    Re: Toggle Macro On/Off

    This is how I have it at it won't toggle off when I double-click on C2. Sorry if I'm doing something dumb, I'm a beginner.

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,481

    Re: Toggle Macro On/Off

    Sorry... my fault... I forgot to give you the change you have to make to your posted code . It should be changed to look like this...
    Please Login or Register  to view this content.
    The arrangement of the code as you posted it is correct... once you make the above change to your SelectionChange event code, everything should work fine.

  6. #6
    Registered User
    Join Date
    11-08-2019
    Location
    Oregon
    MS-Off Ver
    Office 365
    Posts
    30

    Re: Toggle Macro On/Off

    Hmm, still no good. Now it's as if it's toggled off but double-clicking C2 won't get toggle it back on. C2 is a merged cell with C2/C3, could that be a problem?

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,481

    Re: Toggle Macro On/Off

    Yes, of course, Merged Cells are always a problem when code has to work around them. Here is a modification to the BeforeClick event code that should make everything work correctly for you...
    Please Login or Register  to view this content.
    Note: It is best to avoid using Merged Cells if possible as they are always a problem when code is involved; however, if you must use it, then you must mention it when posting future forum questions.

  8. #8
    Registered User
    Join Date
    11-08-2019
    Location
    Oregon
    MS-Off Ver
    Office 365
    Posts
    30

    Re: Toggle Macro On/Off

    Perfect! Works great. Thanks Rick. Noted about the merged cells.

+ 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. [SOLVED] Toggle Hide/Unhide Cols & Toggle adj column width
    By anare in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-20-2018, 11:04 AM
  2. [SOLVED] how do i make a toggle button change other toggle buttons value to false
    By kevinu in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-10-2018, 04:19 PM
  3. Replies: 1
    Last Post: 02-13-2014, 10:55 PM
  4. Hide Row Toggle Macro
    By Battledeck in forum Excel General
    Replies: 1
    Last Post: 08-28-2012, 07:59 PM
  5. Macro in a Toggle Button
    By Preatorian in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-28-2009, 09:20 AM
  6. Macro Toggle On/Off
    By Chipmunk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-15-2006, 03:25 PM
  7. Simple toggle Macro
    By Piranha in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-11-2005, 05:28 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