Strange behavior by Worksheet_Change event

LuckyDPR

New Member
Joined
Aug 6, 2022
Messages
12
Office Version
  1. 2021
Platform
  1. Windows
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If ActiveCell.Row = 1 Then Exit Sub
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    If Not (Application.Intersect(Target, Range("Product[Model]")) Is Nothing) Then              'Say Procedure First
        'Statements
    End If
    If Not (Application.Intersect(Target, Range("Product[Serial]")) Is Nothing) Then              'Say Procedure Second
        'Statements
    End If
    If Not (Application.Intersect(Target, Range("Product[DOP]")) Is Nothing) Then              'Say Procedure Third
        'Statements
    End If
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub

in above code when worksheet_change event is triggered, it takes extra time (Say 2 Seconds) to run PROCEDURE First, whereas PROCDURE Second and PROCEDURE Third runs instantaneously, I have tried above procedures without any statement (DO NOTHING), still results are same, so it is not a problem with codes under these procedures
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Without having access to your workbook, it is hard to say.
What is the exact size of each range?

Also note that in each case, all three IF statements will always run (it will always check all 3 conditions, even if the first one is met).
You might want to try using "Else If" statements, so that if the first runs, the second two don't.
 
Upvote 0
Without having access to your workbook, it is hard to say.
What is the exact size of each range?

Also note that in each case, all three IF statements will always run (it will always check all 3 conditions, even if the first one is met).
You might want to try using "Else If" statements, so that if the first runs, the second two don't.
Range("Product[Model]") have too many dependent cells
whereas other two ranges does not have that many
also my table have around 10000 Rows, but i am wondering if we make the calculations off than ever will it take somehow long because of those dependencies, there is no other difference other than this in these ranges, because as soon as I press enter after typing data in product[Model] Range it take some time to get to the respective IF statement
 
Upvote 0
Range("Product[Model]") have too many dependent cells
whereas other two ranges does not have that many
Well then, I think that probably answers your question, doesn't it?
Quite frankly, if you have around 10000 rows and lots of dependent cells, 2 seconds doesn't seem too unreasonable.

It sounds to me like you might really be dealing with a Relational Database model (whenever I hear of many rows of inter-dependent data, that is often the case).
As such, a Relational Database product like Microsoft Access or SQL may be better suited for your project.
Or perhaps you may want to look at using Power Query if you want to continue to do it in Excel.
 
Upvote 0
Solution
R
Well then, I think that probably answers your question, doesn't it?
Quite frankly, if you have around 10000 rows and lots of dependent cells, 2 seconds doesn't seem too unreasonable.

It sounds to me like you might really be dealing with a Relational Database model (whenever I hear of many rows of inter-dependent data, that is often the case).
As such, a Relational Database product like Microsoft Access or SQL may be better suited for your project.
Or perhaps you may want to look at using Power Query if you want to continue to do it in Excel.
RDBMS, may be, but I don't have that much courage, energy and expertise to do that, apart from that my primary data (Raw Data) Comes from copy paste like operation (although automated), also in excel I can look at data in a glance, hence this approach.
 
Upvote 0
RDBMS, may be, but I don't have that much courage, energy and expertise to do that, apart from that my primary data (Raw Data) Comes from copy paste like operation (although automated), also in excel I can look at data in a glance, hence this approach.
OK, that is fine, but then just be aware that you may have to live with a few of the minor inconveniences of using Excel for purposes for which it was really not designed for.
It can do RDBMS, but since that is not what it was designed for, it can often be a bit clumsy and cumbersome to do so. It is not the best tool for the job, so doesn't handle things as gracefully as a program designed for that purpose.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top