Hi Richard,
Great question. You have an excellent physical Spreadsheet Design, but without knowing a few secrets you created a lot of extra work for yourself. Your application lends itself to one set of TextBoxes for each of the 11 'Code Numbers'. The TextBoxes would be named in such a way that they can be easily recognized:
For Example 'TB501R01C02' would be for 'Code Number '501' Row 01 Column 02.
I don't usually deal with MultiPage UserForms, and I liked your design so much, I fell in love with your application, and went a little overboard.
Your data structure is very well behaved, and lends itself to generalization.
This naming convention is useful because UserForm Controls DO NOT have to be accessed explicitly like you have done. Variable Names can be used:
That solves problem number 1.
-----------------------------------------
It is time consuming and mistake prone to rename all your TextBoxes. I deleted all your TextBoxes and created them Dynamically at runtime. For example for 'Code Number' 501 in Ordinary Code Module ModBudgetFormDynamicTextBoxes:
This solves Problem #2.
-------------------------------
By knowing a few essential items for Each Code Number (Number of Rows, Number of Columns, Starting Row Number on the Spreadsheet) we can create general code for each task such as putting Data In the UserForm, Copying Data From the UserForm to the Spreadsheet, Computing Totals. For example to put Data in the UserForm:
That solves Problem #3.
---------------------------------------
The next item wasn't required, but I added it anyway. To handle TextBox Events (Change, Double Click, Enter the TextBox) you either have to explicitly create an Event Handler Routine in the UserForm Code module for each TextBox for Each Event or a 'Class Event' Handler can be used. The 'Class Event Handler' uses 3 or 4 routines to Handle all TextBox Events. It sounds complicated, but you don't have to understand the details, it is cookbook.
See the attached file. Please let me know if there is anything you don't understand, or any changes you want made. I'm probably stuck in the house in NJ for the next 60 days or more.
Lewis
Bookmarks