+ Reply to Thread
Results 1 to 11 of 11

Run Two Worksheet Change Macros With Different Target Cells

  1. #1
    Registered User
    Join Date
    09-28-2023
    Location
    London, England
    MS-Off Ver
    MS 365 Version 2307 64-bit
    Posts
    24

    Run Two Worksheet Change Macros With Different Target Cells

    Hello,

    I am needing to run two rules on the same sheet using VBA.

    The example sheet is a simplified version of the actual sheet.

    The first thing I need to happen is, when a value in column I is changed to "Complete" the line of data moves over to the sheet named "Archive".
    The second thing I need to happen, as a separate event, is, when the value in column H is changed the whole table is put into ascending order based on the number shown in the cell in column H.

    The two commands on the sheet work independently on separate sheets but I cannot get them to work when added to the same sheet.
    I know I cannot use the "Worksheet_Change" name for both as it throws up the "ambiguous" error but I cannot get the macros to kick in automatically when even when I rename the second command.

    I'm not sure if what I am trying to achieve is impossible but I have been asked to see if I can get it working and it is seriously stretching my very limited knowledge of VBA.

    Any help or advice would be greatly appreciated!

    Many thanks!
    Attached Files Attached Files
    Last edited by EllenAW; 03-21-2024 at 07:11 AM.

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Run Two Worksheet Change Macros With Different Target Cells

    Something like this


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-28-2023
    Location
    London, England
    MS-Off Ver
    MS 365 Version 2307 64-bit
    Posts
    24

    Re: Run Two Worksheet Change Macros With Different Target Cells

    Thank you for your answer.

    The only problem I am now having is that, when the "Complete" row is moved to the "Archive" sheet, I am getting the following error:
    "Run-time error '1004': Sort method of Range class failed

    Any ideas how to combat it?

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Run Two Worksheet Change Macros With Different Target Cells

    I'm not getting that error, but there is no range called "Relabel" in the file you attached.

  5. #5
    Registered User
    Join Date
    09-28-2023
    Location
    London, England
    MS-Off Ver
    MS 365 Version 2307 64-bit
    Posts
    24

    Re: Run Two Worksheet Change Macros With Different Target Cells

    Ah yes, sorry about that; I've amended the file now.
    It's likely because I copied the code from the actual file I need to use it on where there is a named range.

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Run Two Worksheet Change Macros With Different Target Cells

    Try this. I did change the cells in H & I so that they were unprotected.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    09-28-2023
    Location
    London, England
    MS-Off Ver
    MS 365 Version 2307 64-bit
    Posts
    24

    Re: Run Two Worksheet Change Macros With Different Target Cells

    Thank you, that works perfectly now!

    If you have time, would you mind explaining what you did so I can learn for next time?

  8. #8
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Run Two Worksheet Change Macros With Different Target Cells

    Sure
    You had most of it. I used the Select Case statement to determine whether it was column I or H being modified and then ran the different actions accordingly.
    I also used a reference, e.g. cells(1,"I").column rather than 9 as it's easier to read.

  9. #9
    Registered User
    Join Date
    09-28-2023
    Location
    London, England
    MS-Off Ver
    MS 365 Version 2307 64-bit
    Posts
    24

    Re: Run Two Worksheet Change Macros With Different Target Cells

    Thank you, that is really helpful.
    I've made a note for next time!

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,838

    Re: Run Two Worksheet Change Macros With Different Target Cells

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  11. #11
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Run Two Worksheet Change Macros With Different Target Cells

    You're welcome.

+ 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] Worksheet Change Target Ranges
    By Redled89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-03-2016, 08:43 PM
  2. Worksheet Change Target??
    By spinkung in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-29-2009, 05:33 AM
  3. 2 target cells for "Change(ByVal..." worksheet macro
    By timmtamm in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-12-2009, 05:12 PM
  4. [SOLVED] Need to determine the ROW of the TARGET in a Worksheet Change Even
    By Barb Reinhardt in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-04-2006, 09:20 AM
  5. [SOLVED] Excel VBA Target Worksheet change
    By [email protected] in forum Excel General
    Replies: 1
    Last Post: 03-02-2006, 10:40 AM
  6. worksheet change target not recognized
    By Adresmith in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-20-2005, 11:03 AM
  7. Deny change of value of two target cells / enforce use of macros.
    By Ade P in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2005, 12:06 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