Private Sub UserForm_Initialize()
Dim i As Integer, n As Integer
OptionButton1.BackColor = vbBlue
OptionButton2.BackColor = vbGreen
OptionButton3.BackColor = vbYellow
OptionButton4.BackColor = vbRed
With Sheets(1)
For i = 2 To .Range("A65536").End(xlUp).Row + 1
ComboBox1 = .Range("A" & i)
If ComboBox1.ListIndex = -1 Then ComboBox1.AddItem .Range("A" & i)
If .Cells(i, 1).Interior.Color = vbBlue Then
.Cells(i, 1).Font.Color = vbWhite
Else
.Cells(i, 1).Font.Color = vbBlack
End If
Next i
End With
n = 0
For i = 1 To 4
n = n + 1
Me.Controls("OptionButton" & n).Value = False
Next i
Application.EnableEvents = False
TextBox1 = ""
Application.EnableEvents = True
End Sub
Private Sub ComboBox1_Change()
Dim n As Integer
With Sheets(1).Range("a2:a5")
Set cel = .Find(ComboBox1, LookIn:=xlValues)
If Not cel Is Nothing Then
firstAddress = cel.Address
TextBox1.Value = ComboBox1.Value
n = 0
For i = 1 To 4
n = n + 1
If TextBox1.Value = ComboBox1.Value And Me.Controls("OptionButton" & i).BackColor = cel.Interior.Color Then
Me.Controls("OptionButton" & n).Value = True
Else
Me.Controls("OptionButton" & n).Value = False
End If
Next i
End If
End With
End Sub
Private Sub CommandButton1_Click()
Dim n As Integer
TextBox1.Value = ComboBox1.Value
n = 0
For i = 1 To 4
n = n + 1
If Me.Controls("OptionButton" & n).Value = True Then
With Sheets(1).Range("a2:a5")
Set cel = .Find(TextBox1, LookIn:=xlValues)
If Not cel Is Nothing Then
firstAddress = cel.Address
cel.Interior.Color = Me.Controls("OptionButton" & n).BackColor
End If
If cel.Interior.Color = vbBlue Then
cel.Font.Color = vbWhite
Else
cel.Font.Color = vbBlack
End If
End With
End If
Next i
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Sheets(1).Range("a2:a502")
.Interior.ColorIndex = xlNone
.Font.Color = vbBlack
End with
Application.DisplayAlerts = False
ActiveWorkbook.Save
End Sub