Mark
Your error arises because something is going wrong with memory management in the background. This is just my feeling, maybe I'm wrong.
As said previously by PM your code is basically unsafe because there is room for ambiguity to arise when multiple workbooks are opened within the same Excel thread. And you have said your uses typically have many workbooks open, including "multiple copies of this workbook"
. I assume they must be named slightly differently.
You allow users to open a 'modeless' form. This means they can navigate away from the sheet it was originally opened from to any other sheet in your current workbook, or even any sheet in any other workbook opened within the same Excel thread and yet still interact with your form.
You make the assumption throughout your code that the user is not doing this by referring to objects which are basically unqualified. When a reference is said to be unqualified it means there is scope for ambiguity to arise.
For instance:
ThisWorkbook.Worksheets("Points Takeoff").Cells(Copy_Insert_Row, 1).EntireRow.Select
Which workbook are you referring to here? The workbook from which your user originally opened the modeless form or the workbook that is currently active. Your application will crash if the user is not currently using the 'right' workbook or it may even continue to function if the currently active workbook just happened to have a sheet named "Points Takeoff" within it. The point is you don't really know what will happen when multiple workbooks are open, particularly if there is a chance the workbooks are 'clones' of each other.
You need 'Workbooks("BlahBlahBlah").Worksheets("Points Takeoff").Cells(Copy_Insert_Row, 1).EntireRow.Select
No ambiguity possible here.
Another example
Private Sub cbInsert_Row_Click()
tbInsert_Row = Selection.Row
End Sub
1) What is 'tbInset_Row', is it an integer, a string, an object?. You know it is an a text box object on one of your forms but the compiler does not unless it works it out by first scratching its head and then trying to figure out what you mean. Do yourself a favour and give it a hint - ie
Private Sub cbInsert_Row_Click()
Me.tbInsert_Row.Value = Selection.Row
End Sub
2) Exactly what 'Selection' are you referring to here. It is of course the selection on the currently active sheet but you, I think, are assuming it is a selection on the sheet from which the user originally opened the form. This may not be the case because you allow users to navigate away to any sheet.
Some other points
You have about 150 'named range objects' buried in your application. About 100 of these point no where, ie they reference cell ranges which don't exist. They need to be removed.
'Option Explict' should be used everywhere. It should never be optional.
Don't use public variables. Pass parameters directly to subroutines. There is far less scope for confusion.
Just some things to keep you thinking.
2024 RRS on the road
2011 D4 3.0 in the drive way
1999 D2 V8, in heaven
1984 RRC, in hell
Bookmarks