+ Reply to Thread
Results 1 to 11 of 11

How do I include two Private Sub Worksheet_Change’s

  1. #1
    Registered User
    Join Date
    02-01-2009
    Location
    South Wales
    MS-Off Ver
    Excel 2003
    Posts
    25

    Thumbs up How do I include two Private Sub Worksheet_Change’s

    Hi,

    I have two Private Sub Worksheet_Change(ByVal Target As Range) in Sheet 1. One is to force text to Upper case and one is for Validation (automatically add/sort additions). Each one works correctly when it’s placed into the worksheet, but when the second is added I get a ‘Compile Error’ “Ambiguous name detected: Worksheet_Change”.

    Is there a way that I can satisfy both requirements but without this problem occurring.

    Any advice would be greatly appreciated.
    Last edited by Jessy01; 03-23-2011 at 10:58 AM.

  2. #2
    Forum Contributor
    Join Date
    08-19-2010
    Location
    UK.
    MS-Off Ver
    Excel 2007
    Posts
    142

    Re: How do I include two Private Sub Worksheet_Change’s

    I'm not sure but I don't think it's possible.
    Try posting your code and someone may be able to combine the two into one.

  3. #3
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: How do I include two Private Sub Worksheet_Change’s

    Hello,

    you need to put the code into one Sub only, one after the other. Use Goto instead of Exit Sub (where applicable)

    Please Login or Register  to view this content.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,984

    Re: How do I include two Private Sub Worksheet_Change’s

    Quote Originally Posted by teylyn View Post
    Use Goto instead of Exit Sub (where applicable)
    \1

    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Registered User
    Join Date
    02-01-2009
    Location
    South Wales
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: How do I include two Private Sub Worksheet_Change’s

    Hi Teylyn,

    Thanks very much for that, however I'm not quite sure how to do this, would it be possible for you to show me on the attached code please, I tried but failed.

    Thanks for your time.

    J


    Please Login or Register  to view this content.

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: How do I include two Private Sub Worksheet_Change’s

    @romperstomper:

    @Jessy, without looking too much into what the code actually does:

    Please Login or Register  to view this content.
    If you arrange it this way, the first IF statement only runs on the cells that qualify. Then the rest of the code runs in the same event.

    cheers,

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: How do I include two Private Sub Worksheet_Change’s

    @romperstomper: I read you. Just had a lovely dish of spaghetti for dinner....

    @Jessy, without looking too much into what the code actually does:

    Please Login or Register  to view this content.
    If you arrange it this way, the first IF statement only runs on the cells that qualify. Then the rest of the code runs in the same event.

    cheers,

  8. #8
    Registered User
    Join Date
    02-01-2009
    Location
    South Wales
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: How do I include two Private Sub Worksheet_Change’s

    Teylyn,

    Thanks for that, it works fine now. Thanks very much for your time.

    J
    Last edited by Jessy01; 03-23-2011 at 10:53 AM. Reason: Problem resolved

  9. #9
    Registered User
    Join Date
    01-15-2013
    Location
    U.S.A.
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How do I include two Private Sub Worksheet_Change’s

    Hello everyone,

    I am having a similar issue as well. The existing code I have will automatically insert the current date and time in Column 18 when Column 17 status is changed.

    What I want my code to do in addition to, is update Column 30 as well when Column 29 is changed.

    How can I run both under one private sub? Is it possible?

    Any assistance is appreciated. Thanks all!

    Here is my code:
    Attached Files Attached Files
    Last edited by sdpnoy; 01-15-2013 at 05:28 PM.

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: How do I include two Private Sub Worksheet_Change’s

    sdpnoy,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  11. #11
    Registered User
    Join Date
    01-15-2013
    Location
    U.S.A.
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How do I include two Private Sub Worksheet_Change’s

    Thanks arlu1201. I will do that.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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