Why does thjs code trigger another

Giordano Bruno

Well-known Member
Joined
Jan 7, 2007
Messages
1,345
I have a userform with a textbox and a listbox. In the form's code module I have the following code:

Private Sub tbxAB_AfterUpdate()
shtCorrel3.Range("ValidMax").Calculate
End Sub

This code immediately triggers the procedure, "Private Sub lbxSource_Change()".
The calculation of the single cell {ValidMax) is unrelated to the Listbox source. Can anyone explain why it starts the second code and just as importantly how to stop it doing so?
 
See if this workaround works for you :

VBA Code:
Private Sub tbxAB_AfterUpdate()
    lbxSource.Tag = "Calculating"
    shtCorrel3.Range("ValidMax").Calculate
    lbxSource.Tag = ""
End Sub

Private Sub lbxSource_Change()
    'Skip if calculating
    If lbxSource.Tag = "Calculating" Then Exit Sub

    'Your change code code goes here.
End Sub
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Brilliant Rory. I could have thought of that, but I didn't. That's a really neat solution which ticks all the boxes. Thank you again for completing the puzzle for me.
 
Upvote 0

Forum statistics

Threads
1,215,364
Messages
6,124,510
Members
449,166
Latest member
hokjock

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