Hi
Have little experience with usage of public/global subs with MSforms on userforms (UF). I need to declare a public sub over MSform object (eg. textbox). I have 30 command buttons. Each one has a routine, that does something with corresponding textboxes/comboboxes/checkboxes/radiobuttons based on a value from worksheet (YES/NO). I have the code personalized over each object working already without public subs, but is miles long and maintenance is extremly slow at any change.
I would like to shrink the code by declaring public sub to generic MSform object on UF. Now, what I am trying to do is that by clicking on command button, it would call TB101color, this routine declares specific object, checkes if the corresponding value is YES or NO. Based on YES or NO value, routine calls another public routine TB1a or TB1b, both of them are set on generic public object. TB1a is a generic routine, that is suitable for all other similar MSform objects. I hope I am going in the right direction.
Also question is, where do i place this code, on userform or on workbook object?
Public TB1 As MSForms.TextBox
Public Sub TB1a()
Dim TB1 As MSForms.TextBox
TB1.BackColor = RGB(255, 128, 128)
'more code here[size=10]
End Sub
Public Sub TB1b()
Dim TB1 As MSForms.TextBox
TB1.BackColor = RGB(255, 255, 255)
'more code here
End Sub
Sub TB101color()
Dim W2 As Worksheet
Set W2 = Worksheets("TEMP")
Dim TB1 As MSForms.TextBox
Set TB1 = UserForm10.TextBox101
Dim Q As Range
Set Q = W2.Range("AE5")
If Q = "YES" Then
Call TB1a
Else
Call TB1b
End If
End Sub
Display More
thanks for any hints!