Hi.
I have been trying to loop through around 300 text boxes on a form to apply conditional formatting with little success. I have populated the text boxes with the following code:
I have been trying to loop through around 300 text boxes on a form to apply conditional formatting with little success. I have populated the text boxes with the following code:
Code:
TextBox18.Text = Application.VLookup(ComboBox1.Value, Range("C4:NK76"), 7, False)
TextBox19.Text = Application.VLookup(ComboBox1.Value, Range("C4:NK76"), 8, False)
TextBox20.Text = Application.VLookup(ComboBox1.Value, Range("C4:NK76"), 9, False)
TextBox21.Text = Application.VLookup(ComboBox1.Value, Range("C4:NK76"), 10, False)
TextBox22.Text = Application.VLookup(ComboBox1.Value, Range("C4:NK76"), 11, False)
[code/]
as so on up to the 300 text boxes.
I have then tried the following code to try and loop through all the text boxes to check for conditions and then change the back colour accordingly.
[code]
Sub BackColourLoop()
Dim ctl As Control
Dim ctlType As String
ctlType = "Textbox"
For Each ctl In frmHolidayDays.Controls
If TypeName(ctl) = ctrlType Then
If TextBox.Value = "FTJ" Then
TextBox.BackColor = vbRed
ElseIf TextBox.Value = "Sick" Then
TextBox.BackColor = vbGreen
End If
End If
Next ctrl
End Sub,
[code/]
I have tried other ways but nothing is working.
Your help would be much appreciated