+ Reply to Thread
Results 1 to 16 of 16

Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

  1. #1
    Registered User
    Join Date
    02-16-2012
    Location
    London, United Kingdom
    MS-Off Ver
    Excel365 Version 2210
    Posts
    46

    Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Hi All,

    I am trying to run multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one and it gives me an error.

    Could anyone please help me what I did wrong? Please see a code below:


    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Or Target.Column <> 4 Or Target.Row < 3 Then Exit Sub

    Cells(Target.row,5).Value = Now
    End Sub
    If Target.Column = 6 Then

    Dim lastRow As Long
    lastRow = Cells(Rows.Count, 6).End(xlUp).Row
    Range("A3:F" & lastRow).Sort key1:=Range("F3:F42" & lastRow), order1:=xlAscending, Header:=xlNo

    End If

    End Sub


    Thank you in advance!

    Best regards,

    Jan

  2. #2
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Hi Jan,

    You have 2 "End Sub" on your code for what I can see. You should have only one.

    Change this:
    Please Login or Register  to view this content.
    To this:
    Please Login or Register  to view this content.
    Or simply remove that "End Sub" as it terminates your code right there.

    Let me know if that helped.

    BR,
    Filipe


    * If a reply solved or answered your query/question, you can add reputation to the person by clicking on the * Add Reputation
    * When question is resolved, please mark your thread as SOLVED


    Thanks and regards,
    Filipe Oliveira

  3. #3
    Registered User
    Join Date
    02-16-2012
    Location
    London, United Kingdom
    MS-Off Ver
    Excel365 Version 2210
    Posts
    46

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Hi Filipe,

    Thank you for your response.

    Your advice solves the error message but the second part of the code does not do any effect to the excel. The second code is to change order by changing priority. I am not able to attach this file here due its size, so if you want to have a look please follow the link: dropbox.com/s/359hbe8btrhwame/Work%20List.xlsm?dl=0

    Kind regards,

    John

  4. #4
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Remove the unnecessary row 2. The formula in column B contains a circular reference

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Hey John,

    I've twisted a bit your code but it's working from my end.

    It's a longer code but it's working when you change cells on row D.

    Here's the code and let me know if that works:

    Please Login or Register  to view this content.
    Cheers,
    Filipe
    Last edited by pipoliveira; 08-09-2018 at 09:44 AM.

  6. #6
    Registered User
    Join Date
    02-16-2012
    Location
    London, United Kingdom
    MS-Off Ver
    Excel365 Version 2210
    Posts
    46

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Hi Filipe,

    Thank you for the updated code. The code works but there must be still some bug as it doesn't work properly. The priority does not change by changing priority 'F column', but by changing status 'D column'. I attached a screenshots for better explanation.

    I tried to solve the issue in your code, but cannot find the bug. Any idea?

    Many thanks for your help, much appreciated.

    Best regards,

    John
    Attached Images Attached Images

  7. #7
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Hi John,

    Sorry for the late reply.

    I do believe the issue is within the first line of code:
    Please Login or Register  to view this content.
    I do believe changing it would solve the issue but, on the other hand, I tried to run the rest of the code without it and I got an error and the Excel simply crashed.

    I'll leave it for some "Excel Gurus" here to assist you on this part.

    Really sorry for not giving you a solution on this matter.

    Best regards,
    Filipe

  8. #8
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    You missed #4?

  9. #9
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Sorry John,

    Just one other thing.

    This file is huge in size but for what I see, there is no explanation for it as it only contains 2 sheets with no major data on it.

    I would recommend you to create another one from scratch and copy-paste the codes you have.

    This file shouldn't have such a size of 15.6MB.

    Check this old thread as it might help:
    https://www.excelforum.com/excel-pro...d-is-huge.html

    Best regards,
    Filipe

  10. #10
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Hi Vraag,

    I have added the code you've posted on #4 but at least on my side is not working or not doing what John is requesting.

    Column "F" is not sorting automatically.

    I've managed to clean file from 15.6MB size to 2.67MB but for some reason, it still does not allow me to attach it to this thread.

    Best regards,
    Filipe

  11. #11
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Works fine here.Work List.xlsb

  12. #12
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Hi Vraag,

    It is working indeed with the file you've attached.

    Probably this will solve John's query for this thread.

    Thanks a million,
    Filipe

  13. #13
    Registered User
    Join Date
    02-16-2012
    Location
    London, United Kingdom
    MS-Off Ver
    Excel365 Version 2210
    Posts
    46

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Dear Fillipe and Vraag,

    Sorry for late response.

    Thank you very, very much for for your help, much appreciated. Excel works exactly as I needed to.

    Thanks again!

    Best regards,

    John

  14. #14
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368
    Quote Originally Posted by jankrulak View Post
    Dear Fillipe and Vraag,

    Sorry for late response.

    Thank you very, very much for for your help, much appreciated. Excel works exactly as I needed to.

    Thanks again!

    Best regards,

    John
    Glad to help but the credit has to go to Vraag as he/she did not only solved the issue but as well gave you a very small file in size.

    He/she’s code dis not worked on your file because for some reason that you can only tell, that your file had empty row and column after the header.

    Best of luck and, pnce again, gobe credit to Vaag by adding reputation by clicking the “*” sign.

    Best of luck,
    Filipe

  15. #15
    Registered User
    Join Date
    02-16-2012
    Location
    London, United Kingdom
    MS-Off Ver
    Excel365 Version 2210
    Posts
    46

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Hi,

    Sorry I am bothering you again.

    Would you mind help me with the time stamp for the column 'B' base on changes with column 'A' in the macro (the same as for column 'E'if possible)? Current code is way advanced for me. Currently I have a formula in the column 'B', but I would like to rid of it to avoid accidentally deleting of the formula as I will be sharing this project list with my colleagues.

    Thank you in advance and look forward to hearing from you.

    Kind regards,

    John
    Attached Files Attached Files

  16. #16
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Running multiple 'Private Sub Worksheet_Change(ByVal Target As Range)' in one

    Please Login or Register  to view this content.

+ 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] Private Sub Worksheet_Change(ByVal Target As Range)
    By hmr2662 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2015, 12:35 PM
  2. [SOLVED] Combining multiple Private Sub Worksheet_Change(ByVal Target As Range)
    By victortan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-21-2014, 11:12 AM
  3. Private Sub Worksheet_Change(ByVal Target As Range)
    By BigJim68 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-27-2014, 01:57 PM
  4. [SOLVED] Private Sub Worksheet_Change(ByVal Target As Range) End Sub
    By kanonathena in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2013, 12:25 AM
  5. Private Sub Worksheet_Change(ByVal Target As Range) Help
    By adamsj1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-28-2012, 09:17 AM
  6. [SOLVED] Private Sub Worksheet_Change(ByVal Target As Range)
    By adamsj1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-12-2012, 03:36 AM
  7. [SOLVED] Private Sub Worksheet_Change(ByVal Target As Range)
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-18-2012, 01:13 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