I believe that you are looking for something like this.
We are adding a boolean flag so that we can use it ( cf
).
We can Resize
MergeArea
instead of the cell value itself.
If there are merged cells, this allows for this area - if not, it will not.
Then add the potential counter MergeArea
to our row counter ( Zeile
).
Sub ColorEveryOther()
Dim cf As Boolean
Dim Zeile As Long
Dim lr As Long
lr = ActiveSheet.UsedRange.Rows.CountLarge
For Zeile = 1 To lr
If Not cf Then Range("A" & Zeile).MergeArea.Resize(, 8).Interior.ColorIndex = 15
Zeile = (Zeile + Range("A" & Zeile).MergeArea.Cells.CountLarge) - 1
cf = Not cf
Next Zeile
End Sub
Results:
EDIT:
This is your code updated.
I also cleared the previous code a bit.
Sub test()
Dim Zeile As Long
Dim cf As Boolean
With Tabelle2
For Zeile = 1 To .UsedRange(Rows.Count).End(xlUp).Row
If cf = False Then .Cells(Zeile, 1).MergeArea.Resize(, 8).Interior.ColorIndex = 15
Zeile = (Zeile + .Cells(Zeile, 1).MergeArea.Cells.CountLarge) - 1
cf = Not cf
Next
End With
End Sub
:
cf = Not cf
- :
If cf = True Then
cf = False
Else
cf = True
End If
cf = False
.
cf = Not False
= True
cf = Not True
= False
, :)
, MOD
, .