My beginners code [which works perfectly well] uses multiple IF statements. My question is [before I go any further because I will have lots of textboxes [txtbx#] is there any downside of coding this way ?
The user will be typing 40-50 short strings into textboxes while someone reads them to him then clicks a button to fill color all the matches in the worksheet column;
Private Sub CommandButton1_Click()
Dim i As Integer
Dim AbbNum As String
Dim AbbNum2 As String
Dim AbbNum3 As String
Dim AbbNum4 As String
Dim AbbNum5 As String
Dim c As Integer
Dim MySheet As Worksheet
Set MySheet = Sheets(2)
c = MySheet.Cells(Rows.Count, 2).End(xlUp).Row
For i = 2 To c
AbbNum = txtbxONE.Value
If Cells(i, 1).Value = AbbNum Then
Cells(i, 1).Interior.ColorIndex = 6
End If
AbbNum2 = txtbxTWO.Value
If Cells(i, 1).Value = AbbNum2 Then
Cells(i, 1).Interior.ColorIndex = 6
End If
AbbNum3 = txtbxTHREE.Value
If Cells(i, 1).Value = AbbNum3 Then
Cells(i, 1).Interior.ColorIndex = 6
End If
AbbNum4 = txtbxFOUR.Value
If Cells(i, 1).Value = AbbNum4 Then
Cells(i, 1).Interior.ColorIndex = 6
End If
AbbNum5 = txtbxFIVE.Value
If Cells(i, 1).Value = AbbNum5 Then
Cells(i, 1).Interior.ColorIndex = 6
End If
Next i
End Sub
forloop the value of a cell will be compared against all the checkbox contents, is it intentional?