использовать диапазоны и длинные. Переместите набор в l oop.
Dim i As Long
Dim RowCount As Long
Dim category As Range
Dim product As Range
Dim quantity As Range
With Sheets("Sheet1")
RowCount = .Cells(.Rows.Count, 1).End(xlUp).Row
' Another way to count the number of rows needed
For i = 2 To RowCount
Set category = .Cells(i, 1)
Set product = .Cells(i, 2)
Set quantity = .Cells(i, 3)
' insert the IF/THEN/ELSE structure here to
' format the font color of Fruits to blue,
' and the rest of the others to magenta
If category = "Fruits" Then
category.Font.Color = vbBlue
product.Font.Color = vbBlue
quantity.Font.Color = vbBlue
Else
category.Font.Color = vbMagenta
product.Font.Color = vbMagenta
quantity.Font.Color = vbMagenta
End If
Next
End With
или пропустите переменные:
With Sheets("Sheet1")
Dim RowCount As Long
RowCount = .Cells(.Rows.Count, 1).End(xlUp).Row
Dim i As Long
For i = 2 To RowCount
' insert the IF/THEN/ELSE structure here to
' format the font color of Fruits to blue,
' and the rest of the others to magenta
If .Cells(i, 1) = "Fruits" Then
.Range(.Cells(i, 1), .Cells(i, 3)).Font.Color = vbBlue
Else
.Range(.Cells(i, 1), .Cells(i, 3)).Font.Color = vbMagenta
End If
Next
End With