Continuous Macro with Activate and Change - stack space error

treepanic

New Member
Joined
May 30, 2014
Messages
4
Hello, all! I have a very similar situation except I can't get the second part to work. I have an order form with certain items that need to be ordered in quantities of six. The "Worksheet_Activate()" bit works; if I click into 'Sheet 2' and back into 'Sheet 1', the macro auto-runs and rounds the quantities in the select cells to multiples of 6.

Here's my code:

Private Sub Worksheet_Activate() 'This part is working fine
For Each cell In [N46:N51, N56:N59]
If cell = " " Then Exit Sub
cell.Value = Application.MRound(cell.Value, 6)
Next cell
End Sub


Private Sub Worksheet_Change(ByVal Target As Range) 'This part isn't working
For Each cell In [N46:N51, N56:N59]
If cell = " " Then Exit Sub
cell.Value = Application.MRound(cell.Value, 6)
Next cell
End Sub

The error I receive is "Run-time error '28': Out of stack space"; when I click to debug, "For Each cell In [N46:N51, N56:N59]" (under 'Worksheet_Change...") is highlighted.

Any ideas?

Thanks!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Because your procedures are changing the cells you need to disable the Worksheet_Change event procedure. Put this at the beginning of your procedures:

Application.EnableEvents = False

and set it back to True at the end.
 
Upvote 0
Awesome! For the record, this is my final, working script:

Private Sub Worksheet_Activate() 'This part is working fine
For Each cell In [N46:N51, N56:N59]
If cell = " " Then Exit Sub
cell.Value = Application.MRound(cell.Value, 6)
Next cell
End Sub


Private Sub Worksheet_Change(ByVal Target As Range) 'This part isn't working
Application.EnableEvents = False
For Each cell In [N46:N51, N56:N59]
If cell = " " Then Exit Sub
cell.Value = Application.MRound(cell.Value, 6)
Next cell
Application.EnableEvents = True
End Sub

Thanks for all your help!
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

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