delaying Worksheet_Calculate event or write data in before it gets sorted

tomanton

New Member
Joined
Jan 28, 2014
Messages
26
Hi excel gurus. I've got a user form which collects some metadata. For users convenience this metadata gets sorted in a s/s by two columns J & L with a worksheet calculate event. the problem occurs with data that is beyond sorted column J, so whatever gets written in columns further to it doesn't get sorted in line with the rest data. My question would be is there a way to write data from user form before worksheet calculate event kicks in? or any other workaround. I'll try removing worksheet calculate event and add sorting in a sub which will be called after data gets written in. will update on the outcome.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Sorted! it worked with calling a sub at the end of writing data in, instead of having worksheet calculate event
 
Upvote 0
well to my surprise at the beginning no! but then I added msgboxes to see when worksheet calculate event gets fired. So when I submit data on userform it gets written cell by cell and worksheet calculate even is called after each cell! I thought at first worksheet calculate event would start after everything gets written
 
Upvote 0
You can suppress the event with:

Code:
Application.EnableEvents = False

Set it back to true when you want to re-enable the event.
 
Upvote 0
well I did, that's why I had but it didn't work
Code:
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
MsgBox "starts here", vbOKCancel
'original data range
'Range("b3:l23").Sort Key1:=Range("J3:J23"), Order1:=xlAscending, Header:=xlYes, _
'new extented range
Range("b3:P23").Sort Key1:=Range("J3:J23"), Order1:=xlAscending, Header:=xlYes, _
Key2:=Range("L3:L23"), Order2:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, _
          Orientation:=xlTopToBottom
Application.EnableEvents = True
MsgBox "finishes here", vbOKCancel
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,769
Messages
6,126,787
Members
449,336
Latest member
p17tootie

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