原來VBA稍修改就可以
Sub test()
Dim m&, n&, k&, rag As Range, ragA As Range
Application.ScreenUpdating = False
Range("k6").CurrentRegion.Offset(5, 0).Interior.ColorIndex = -4142
For Each rag In Range("k6").CurrentRegion.Offset(5, 0)
If rag <> "" And rag.Interior.ColorIndex = -4142 Then
Set ragA = rag: m = 1
Do Until rag.Offset(m, m * 2) = ""
Set ragA = Application.Union(ragA, rag.Offset(m, m * 2))
m = m + 1
Loop
If m = 2 Then ragA.Interior.ColorIndex = 3
If m = 3 Then ragA.Interior.ColorIndex = 45
If m > 3 Then ragA.Interior.ColorIndex = 23
m = 0
Set rag = Nothing
End If
Next
Application.ScreenUpdating = True
End Sub