I know very little about VBA code, but I managed to copy and paste code(s) from various site to create a userform. I have multiple TextBoxes (i.e., TextBox1 thru TextBox15) on the userform. I would like 10 of the 15 text boxes formatted with the same code (see below). I copied the code 10 times, then changed the name (e.g., TextBox1, TextBox2 ....TextBox10) so the code is just repeats.
Is it possible to reduce the amount of code and apply the code below it to the 10 TextBoxes that uses the same format with having to repeat the code?
Private Sub TextBox1_Change()
With TextBox1
If .Value < 0 Then
.BackStyle = fmBackStyleTransparent
.ForeColor = fmBackStyleTransparent
.ForeColor = RGB(255, 0, 0)
Else
.ForeColor = fmBackStyleTransparent
.ForeColor = RGB(0, 0, 0)
End If
End With
End Sub
Thank you
Is it possible to reduce the amount of code and apply the code below it to the 10 TextBoxes that uses the same format with having to repeat the code?
Private Sub TextBox1_Change()
With TextBox1
If .Value < 0 Then
.BackStyle = fmBackStyleTransparent
.ForeColor = fmBackStyleTransparent
.ForeColor = RGB(255, 0, 0)
Else
.ForeColor = fmBackStyleTransparent
.ForeColor = RGB(0, 0, 0)
End If
End With
End Sub
Thank you
Last edited: