UserForm Malfunctioning after 70 plus calls

StreetSwan

New Member
Joined
Aug 24, 2021
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
Good Afternoon all!
I am a noob to vba and have been working on a project for work. It's basically an inspection form for our machined parts.
We measure the part with the caliper, the measurement goes into the userfrom and then gets transferred to the next empty cell in the corresponding column. It is a back and forth between the thickness and the width of the part. The code works great up until i get to 70 or so measurements in, then i get a run time error method range of object worksheet failed. I have tried everything i can think of and so far nothing has worked. Can someone please help me understand this?
I have the following code to execute:

Private Sub Enter_Click()
'Finds next empty cell and places the value in it
eRow = Measurements.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
Cells(eRow, 2).Value = RadialTB.Value
'Adds beep to notify inspector
Beep
'Acitvates the cell so the it will page down as necessary
Cells(eRow, 2).Activate
'Allows switching back and forth between stagnant and alternating
If StagnantCB.Value = True Then
RadialTB.Value = ""
RadialTB.SetFocus
Else
Unload Me
GrindEnter.Show (this is where the code is breaking)
End If
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this.
1. Step through the code with F8. If that doesn't give you a clue then
2. In VBA Editor, open Tools-Options. Open the General tab and in "Error Trapping" select "Break On All Errors". See where it would take you. Don't forget to re-select "Break on Unhandled Errors" when you are done.

Shift+F8 would step through calls to other subs in 1 step, instead of stepping all lines inside that sub.
 
Upvote 0
Try this.
1. Step through the code with F8. If that doesn't give you a clue then
2. In VBA Editor, open Tools-Options. Open the General tab and in "Error Trapping" select "Break On All Errors". See where it would take you. Don't forget to re-select "Break on Unhandled Errors" when you are done.

Shift+F8 would step through calls to other subs in 1 step, instead of stepping all lines inside that sub.
Hi thanks for the quick reply! I Turned on break on all errors, which showed me a break at the userform initialize code. To test that issue I commented out the code on both userforms. I ran the program again and about 70-75 entries in I got a stack overflow error at the grindenter.show step.
 
Upvote 0
It may be that your code is recursive, as in one sub calls the other, and the other call first one. This results in a neverending execution, filling the call stack with each call. Call stack in VBA iirc is 1MB in size. In your case it takes 70 calls to fill it. You have to device a different approach to break this recursion.
 
Upvote 0
You can try instead to show the next userform with application.run (not sure it would work) or application.ontime coupled with DoEvents. This would ensure the calling sub actually continue executing and finish. Not at home atm to test.

Edit: You cant app.ontime to a sub on a userform but you can have a simple proxy sub that show the userform.
 
Upvote 0
It may be that your code is recursive, as in one sub calls the other, and the other call first one. This results in a neverending execution, filling the call stack with each call. Call stack in VBA iirc is 1MB in size. In your case it takes 70 calls to fill it. You have to device a different approach to break this recursion.
This would explain why it happens roughly at the same time every time. I suppose I will have to come up with some other way to approach this. Thanks
 
Upvote 0
You can try instead to show the next userform with application.run (not sure it would work) or application.ontime coupled with DoEvents. This would ensure the calling sub actually continue executing and finish. Not at home atm to test.

Edit: You cant app.ontime to a sub on a userform but you can have a simple proxy sub that show the userform.
Are you saying to create sub "x" that calls the userform, then call sub "x" from my code? Sorry if that doesn't make any sense, but I do not know what a proxy sub is...
 
Upvote 0
Just a normal sub on a normal module with only a userform.show inside.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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