Hi all,
I was wondering if someone could give me some assistance on the following issue. I have created the below userform, and when an Agent name is selected from the Combo Box and the "Retrieve" command button is pressed, the text boxes below populate as shown (NB:agent name has been removed)
What I am trying to do is show conditional formatting in each of the text boxes, all with the same criteria:
"YES" = Green background
"NO" = Red background
"-" = Grey background
Here is the code I did in order to use the combobox/command box to populate the text boxes...
Private Sub CommandButton5_Click()
Dim criteria As String
Dim rng As Range
Dim result
criteria = ComboBox1.Text
If Trim(criteria) <> "" Then
result = Application.Match(criteria, Worksheets("QtrData").Range("B:B"), 0)
If Not IsError(result) Then
With Worksheets("QtrData")
TextBox5.Text = .Range("I:I")(result).Text
TextBox6.Text = .Range("M:M")(result).Text
TextBox10.Text = .Range("R:R")(result).Text
TextBox14.Text = .Range("W:W")(result).Text
TextBox18.Text = .Range("AB:AB")(result).Text
TextBox22.Text = .Range("AC:AC")(result).Text
TextBox2.Text = .Range("AH:AH")(result).Text
TextBox7.Text = .Range("AL:AL")(result).Text
TextBox11.Text = .Range("AQ:AQ")(result).Text
TextBox15.Text = .Range("AV:AV")(result).Text
TextBox19.Text = .Range("BA:BA")(result).Text
TextBox23.Text = .Range("BB:BB")(result).Text
TextBox3.Text = .Range("BG:BG")(result).Text
TextBox8.Text = .Range("BK:BK")(result).Text
TextBox12.Text = .Range("BP:BP")(result).Text
TextBox16.Text = .Range("BU:BU")(result).Text
TextBox20.Text = .Range("BZ:BZ")(result).Text
TextBox24.Text = .Range("CA:CA")(result).Text
TextBox4.Text = .Range("CF:CF")(result).Text
TextBox9.Text = .Range("CJ:CJ")(result).Text
TextBox13.Text = .Range("CO:CO")(result).Text
TextBox17.Text = .Range("CT:CT")(result).Text
TextBox21.Text = .Range("CY:CY")(result).Text
TextBox25.Text = .Range("CZ:CZ")(result).Text
TextBox26.Text = .Range("DA:DA")(result).Text
End With
Else
MsgBox "Unable to find reference"
End If
Else
MsgBox "Unable to find reference"
End If
End Sub
Hope you can help!!!
I was wondering if someone could give me some assistance on the following issue. I have created the below userform, and when an Agent name is selected from the Combo Box and the "Retrieve" command button is pressed, the text boxes below populate as shown (NB:agent name has been removed)
What I am trying to do is show conditional formatting in each of the text boxes, all with the same criteria:
"YES" = Green background
"NO" = Red background
"-" = Grey background
Here is the code I did in order to use the combobox/command box to populate the text boxes...
Private Sub CommandButton5_Click()
Dim criteria As String
Dim rng As Range
Dim result
criteria = ComboBox1.Text
If Trim(criteria) <> "" Then
result = Application.Match(criteria, Worksheets("QtrData").Range("B:B"), 0)
If Not IsError(result) Then
With Worksheets("QtrData")
TextBox5.Text = .Range("I:I")(result).Text
TextBox6.Text = .Range("M:M")(result).Text
TextBox10.Text = .Range("R:R")(result).Text
TextBox14.Text = .Range("W:W")(result).Text
TextBox18.Text = .Range("AB:AB")(result).Text
TextBox22.Text = .Range("AC:AC")(result).Text
TextBox2.Text = .Range("AH:AH")(result).Text
TextBox7.Text = .Range("AL:AL")(result).Text
TextBox11.Text = .Range("AQ:AQ")(result).Text
TextBox15.Text = .Range("AV:AV")(result).Text
TextBox19.Text = .Range("BA:BA")(result).Text
TextBox23.Text = .Range("BB:BB")(result).Text
TextBox3.Text = .Range("BG:BG")(result).Text
TextBox8.Text = .Range("BK:BK")(result).Text
TextBox12.Text = .Range("BP:BP")(result).Text
TextBox16.Text = .Range("BU:BU")(result).Text
TextBox20.Text = .Range("BZ:BZ")(result).Text
TextBox24.Text = .Range("CA:CA")(result).Text
TextBox4.Text = .Range("CF:CF")(result).Text
TextBox9.Text = .Range("CJ:CJ")(result).Text
TextBox13.Text = .Range("CO:CO")(result).Text
TextBox17.Text = .Range("CT:CT")(result).Text
TextBox21.Text = .Range("CY:CY")(result).Text
TextBox25.Text = .Range("CZ:CZ")(result).Text
TextBox26.Text = .Range("DA:DA")(result).Text
End With
Else
MsgBox "Unable to find reference"
End If
Else
MsgBox "Unable to find reference"
End If
End Sub
Hope you can help!!!