Hello all,
I have a UserForm with lots of textboxes (few dozens). I'm aiming at making it idiot- and mistake-proof so each textbox has some safety behaviours triggered by change events.
The simpliest and most common one is changing background colour upon value change. The code is like this:
Thing is, I have to copy and paste these lines for each individual textbox, changing the textbox number in each one. As the result, my code is of enormous size, hard to analyze and search.
Is there a way, to create some universal colour-changing (and other) instruction, that could be called out by value change event? I imagine it would require some variable, which would be a textbox number, so the function could "knew" which textbox is to change exactly.
My VBA knowledge is not very wide, I almost never use "modules" or "class modules" since I don't really understand their purpose but in this case I feel they might be useful. Any help?
I have a UserForm with lots of textboxes (few dozens). I'm aiming at making it idiot- and mistake-proof so each textbox has some safety behaviours triggered by change events.
The simpliest and most common one is changing background colour upon value change. The code is like this:
VBA Code:
Private Sub TextBox387_Change()
With TextBox387
If .Value = "" Then
.BackColor = RGB(255, 200, 200)
Else
.BackColor = RGB(200, 255, 200)
End If
End With
End Sub
Thing is, I have to copy and paste these lines for each individual textbox, changing the textbox number in each one. As the result, my code is of enormous size, hard to analyze and search.
Is there a way, to create some universal colour-changing (and other) instruction, that could be called out by value change event? I imagine it would require some variable, which would be a textbox number, so the function could "knew" which textbox is to change exactly.
My VBA knowledge is not very wide, I almost never use "modules" or "class modules" since I don't really understand their purpose but in this case I feel they might be useful. Any help?