Sub test()
Dim MyCell As Range, i As Long
Dim SelectedRange As Range
Set SelectedRange = Application.InputBox("Select Range", Type:=8)
Dim SplitRow As Long
SplitRow = Application.InputBox("Split Row Num", Type:=1)
Dim FormatRange As Long
FormatRange = SelectedRange.Rows.Count / SplitRow
Application.ScreenUpdating = False
For Each MyCell In SelectedRange
If i < FormatRange Then
MyCell.Interior.Color = vbRed
i = i + 1
Else
MyCell.Interior.Color = vbYellow
End If
Next MyCell
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
Sub test()
Dim selectedRange As Range, splitRow As Long, formatRange As Long, i As Long
Set selectedRange = Application.InputBox("Select Range", Type:=8)
splitRow = Application.InputBox("Split Row Num", Type:=1)
Application.ScreenUpdating = False
With selectedRange
formatRange = .Rows.Count / splitRow
For i = 1 To .Rows.Count Step formatRange
.Cells(i, 1).Resize(formatRange, 1).Interior.ColorIndex = i / formatRange + 3
Next i
End With
Application.ScreenUpdating = True
End Sub