Sub Color_H()
Dim i As Long
Dim iLastRow As Long
Dim j As Integer
Dim k As Integer
Dim j_b As Integer
Dim j_e As Integer
Dim iLastColumn As Integer
iLastRow = Cells(Rows.Count, "B").End(xlUp).Row
iLastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, 2), Cells(iLastRow, iLastColumn)).Interior.ColorIndex = xlColorIndexNone
For i = 2 To iLastRow
For j = 2 To iLastColumn
If Cells(i, j) = "Н" Then
j_b = j: k = 0
Do
j_e = j + k
k = k + 1
Loop While Cells(i, j_b + k) = "Н"
If k >= 3 Then Range(Cells(i, j_b), Cells(i, j_e)).Interior.ColorIndex = 3
j = j_e
End If
Next
Next
End Sub
Sub Color_H2()
Dim r&, rg As Range, a As Range: r = 2
Do While Not IsEmpty(Cells(r, 2))
Set rg = Cells(r, 2).Resize(1, 25): rg.Replace "Н", Empty, xlValue
If WorksheetFunction.CountBlank(rg) > 0 Then
For Each a In rg.SpecialCells(xlCellTypeBlanks).Areas
If a.Count > 2 Then a.Cells.Interior.Color = RGB(255, 255, 0)
a.Cells.Value = "Н"
Next
End If
r = r + 1
Loop
End Sub
Kuzmich, а почему i as long, а j as integer? Типы данных Integer В последних версиях VBA преобразует все целые значения в тип Long , даже если они объявлены как тип Integer . Так что больше нет преимущества в производительности с помощью целочисленных переменных; на самом деле, длинные переменные могут быть немного быстрее , потому что VBA не придется конвертировать их.
Изменено: АlехМ - 19.06.2017 23:40:25(Добавил фразу из статьи по ссылке.)