+ Reply to Thread
Results 1 to 14 of 14

Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

  1. #1
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    209

    Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Hello All,

    I have excel file where in I have included 2 logics for Private Sub Worksheet_Change(ByVal Target As Range).

    In sheet1, we have cell K4 which is ERP and this is drop down. Once we select value from the drop down, it should display message to clear all the details. Once the details are cleared, then we should select values based on the ERP selected which is col J. Col J is again a drop-down which gives source CoCo values for the ERP selected. These source and Target values are in sheet 2.

    In my code, I have the logic to clear the values upon ERP selection and to populate target values based on source are in the same block

    Private Sub Worksheet_Change(ByVal Target As Range)

    Not sure, if this is causing issue in clearing the values when selecting ERPs. Also, while populate target value which is the second section of the code, I am referring to cell K4.

    This is just for Coco. I need to replicate the same for other fields like Acct as well. If I include the logic for all the columns in Worksheet_Change and try to select ERP, then the file just hangs.
    Attached Files Attached Files

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Try disabling events in the first part of your code also.

  3. #3
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    209

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Hello,

    Thanks for quick reply.

    I updated the code. Now what I see is, Target values are not getting cleared.

    Please find attached the file.
    Attached Files Attached Files

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Possibly...
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    209

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Hello,

    I updated the code, but do not see target values coming.

    Also, if we do a copy paste of multiple values, that is also not populating target members.

    Attached the file. Please advise.

    Thanks in advance.
    Attached Files Attached Files

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Try this...
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    209

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Thank you. This works for few members.

    But, we have users who try to copy 1000+ members in source column. In that scenario, we see target values populating one at a time which is taking time to populate target for 1000+ members.

    Is there a way we can improve the performance if we select multiple source members at a time.

    Also, we see calculating (8 Threads) running for a very long time and hangs the excel.

    Thanks in advance
    Last edited by BMD4; 05-25-2022 at 04:34 PM.

  8. #8
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Instead of VBA, you might try putting your lookup formula into the cells in column b before you paste.

  9. #9
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    209

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Hello,

    Please let me know if you are looking for actual formula in excel.

    I have initially setup excel formula instead of VBA.

    But formulas are taking time to execute as the formula extends for 2000 rows.

    So, I am looking to replace excel formula with VBA to improve performance

  10. #10
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Whether the lookup formula is in vba or on the worksheet, it needs to be calculated using worksheet ranges, and that takes time. You might get better results looping through the data using arrays.

  11. #11
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,251

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Try turning off more than just events for the duration of the calculation:
    Please Login or Register  to view this content.
    Artik

  12. #12
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    209

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Thanks Artik.

    I have added the calculation lines to the code. However, did not see much difference.

    Can you please help me understand if this reduces calculation time.

  13. #13
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Possibly using a dictionary to capture your data first...
    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,251

    Re: Private Sub Worksheet_Change(ByVal Target As Range) issue in VBA

    Quote Originally Posted by BMD4 View Post
    I have added the calculation lines to the code. However, did not see much difference.

    Can you please help me understand if this reduces calculation time.
    After reading about the long running problem, I concluded that it may be due to the large number of formulas in the workbook. Since not much changed after adding the code I suggested, from this I conclude that the cause is not the formulas.
    That is, the cause may lie in the method used in the code itself. I will admit that I have tried multiplying the data and inserting 1000 items into column "J", but I did not notice a significant degradation in execution time.

    Artik

+ 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. Private Sub Worksheet_Change(ByVal Target As Range)
    By PIM499 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2019, 01:07 AM
  2. [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
  3. [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
  4. 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
  5. [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
  6. [SOLVED] Private Sub Worksheet_Change(ByVal Target As Range)
    By Arturo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-25-2005, 11:06 AM
  7. Private Sub Worksheet_Change(ByVal Target As Range)
    By bondcrash in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2005, 02:59 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