+ Reply to Thread
Results 1 to 9 of 9

Trying to have two events in the worksheet change code

  1. #1
    Registered User
    Join Date
    07-20-2019
    Location
    Virginia
    MS-Off Ver
    2013
    Posts
    5

    Trying to have two events in the worksheet change code

    Hi,
    Very much a newbie but trying to get two different bits of code to run in the worksheet code.

    As is now the worksheet change reads as below the dashed lines:

    ----------------------------------------------------------------

    Please Login or Register  to view this content.
    _____________________________________________________________________

    But I want to add this to run there as well:


    Please Login or Register  to view this content.

    I have tried to copy other solutions to combine them but when I do I cant make them work. Any help really appreciated! This my first post so I apologize if I posted this incorretly. Thanks
    Sherman
    Last edited by shermanwar; 07-24-2019 at 06:11 PM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Trying to have two events in the worksheet change code

    If you click Edit on your post, then select the part that is code and click the pound symbol (#) in the tool bar, it will add code tags so your code will retain its formatting and appear in a box like below.

    Try this to see if it does what you want with the worksheet change event.

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    07-20-2019
    Location
    Virginia
    MS-Off Ver
    2013
    Posts
    5

    Re: Trying to have two events in the worksheet change code

    JLGWhiz, Thank you VERY much for teaching me that! I think knowing that will help me explain what I am trying to do. Much appreciated! Now that I have it formatted correctly would you mind taking another look? The code in the second window is for creating a data bar in cells with a format based on being positive or negative numbers. I didnt see it in your answer (again because it I didnt know how to post it right) Thank you again for your help!!!

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Trying to have two events in the worksheet change code

    The code in post #2 combines your two Worksheet_Change event macros and should do what you want. Did you try it?

    The 'TwoColours' code would need to be in module1 for it to work properly.
    Last edited by JLGWhiz; 07-25-2019 at 08:07 AM.

  5. #5
    Registered User
    Join Date
    07-20-2019
    Location
    Virginia
    MS-Off Ver
    2013
    Posts
    5

    Re: Trying to have two events in the worksheet change code

    Hi, The time format part works just fine but the part I couldn't get to work was making the time format and the Twocolours code both work. I inserted the code and created Module 1 for the Twocolours code. As before the time format works fine but the twocolours code does not appear to run.

    Thoughts?

    And again Thank you for helping me!!

  6. #6
    Registered User
    Join Date
    07-20-2019
    Location
    Virginia
    MS-Off Ver
    2013
    Posts
    5

    Re: Trying to have two events in the worksheet change code

    Hi again! I made one small change of adding a the Call command and now it works in that any time I enter the time in one of time format cells its runs the data bar format update. That's very close to total success! Is there a way to make twocolours only fire when cells that effect it change (vice any time format cell)? That is to say there are a lot of cells that are covered by the time format code but only a few for that twocolours really apply to.


    Please Login or Register  to view this content.

  7. #7
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Trying to have two events in the worksheet change code

    Please Login or Register  to view this content.
    If the target cell being changed is in the range with red font, then the TwoColours code should run. It will not run if the change occurs in any other range. So set your parameters for the trigger range in this statement. I enclosed the call statement in an If Then statement so that if the change in column H caused an error the code TwoColours code would not run. If you want it to run although column H errors, then remove the 'If Err.Number' statement and its 'End If' . But it will still require the parameters to be set to the range you want th change event to trigger the code on.

    The change you made will cause the TwoColours code to run any time a change is made to the sheet.
    This is what you want to work with to get it to operate correctly.

    Please Login or Register  to view this content.
    Last edited by JLGWhiz; 07-25-2019 at 05:23 PM.

  8. #8
    Registered User
    Join Date
    07-20-2019
    Location
    Virginia
    MS-Off Ver
    2013
    Posts
    5

    Re: Trying to have two events in the worksheet change code

    Thank you so much! That did it! Sorry for my delay, but life got in the way of efforts in Excel. Thank you for sharing your time and knowledge. It is Greatly appreciated!!!!!!!

  9. #9
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Trying to have two events in the worksheet change code

    You're welccome,
    regards, JLG
    Last edited by AliGW; 07-28-2019 at 02:46 AM. Reason: Please don't quote unnecessarily!

+ 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] Run 2 change events on the same worksheet
    By macquhele in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-08-2015, 05:42 PM
  2. 2 change events on the same worksheet
    By aaron_burr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-22-2015, 03:47 PM
  3. VBA code for ADD and CHANGE events for Combo Box on worksheet
    By carlliebenberg in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-18-2014, 06:16 AM
  4. Worksheet Change and Worksheet Activate Events Reprotecting Automatically
    By excelnewb02 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-21-2012, 08:44 PM
  5. Combine 2 worksheet change events
    By akderitend in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-07-2012, 06:57 PM
  6. Multiple Worksheet Change Events
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 12-13-2010, 06:14 PM
  7. Multiple change events in one worksheet?
    By JBW in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-22-2009, 01:33 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