I have built a fairly complex userform with multiple tabs (about 20 tabs). Each tab asks the user to enter values into several textboxes with a sum textbox on the tab. I have figured out how to use the afterupdate event to sum all the texbox values after any are changed and place the sum in the totals box.
Here's my current code for one afterupdate event.
Problem is that this requires an afterupdate event for each box. By the time I do this there will be dozens of instances of basically the same code repeated over and over. Obviously, this gets to be very laborious to build and is prone to human error (my vba skills are novice at best).
Ideally what I'd like is to have one afterupdate event that watches all textboxes in a defined group. Then anytime updates are made to any textbox in that group then a macro is called that sums up all the values and places the total in the txtSUM box.
Originally I took the code above ( txtSUM.Value = Int(txtBOX1.Value) + Int(txt.BOX2.Value) + Int(txtBOX3.Value) and placed it in a module. I then called the module from the afterupdate event for each textbox. Much to my chagrin that didn't work. Like I said, my vba skills are weak.
In my research I found this thread over at Stackoverflow. User Roy uses a class module and userform module to do what I want structurally. He uses it to produce an msg box when someone enters a non-numeric value. I just want to add to that the summation of textboxes. I got his code to work with my userform so at least I know the basic solution works. Problem is that my vba skills aren't strong enough to modify for my need.
Any help would be greatly appreciated. Thanks in advance.
Here's my current code for one afterupdate event.
Private Sub txtBOX1_AfterUpdate()
txtSUM.Value = Int(txtBOX1.Value) + Int(txt.BOX2.Value) + Int(txtBOX3.Value)
End Sub
Problem is that this requires an afterupdate event for each box. By the time I do this there will be dozens of instances of basically the same code repeated over and over. Obviously, this gets to be very laborious to build and is prone to human error (my vba skills are novice at best).
Ideally what I'd like is to have one afterupdate event that watches all textboxes in a defined group. Then anytime updates are made to any textbox in that group then a macro is called that sums up all the values and places the total in the txtSUM box.
Originally I took the code above ( txtSUM.Value = Int(txtBOX1.Value) + Int(txt.BOX2.Value) + Int(txtBOX3.Value) and placed it in a module. I then called the module from the afterupdate event for each textbox. Much to my chagrin that didn't work. Like I said, my vba skills are weak.
In my research I found this thread over at Stackoverflow. User Roy uses a class module and userform module to do what I want structurally. He uses it to produce an msg box when someone enters a non-numeric value. I just want to add to that the summation of textboxes. I got his code to work with my userform so at least I know the basic solution works. Problem is that my vba skills aren't strong enough to modify for my need.
Any help would be greatly appreciated. Thanks in advance.