I'm trying to loop through different ranges replacing the cells with the value '1' with another value/format.
If I use the ranges one by one, it works great. But when I'm trying to combine the different ranges and loop through the array I'm getting an Application-defined Runtime error at the .Pattern part.
I've read it has something to do with not defining the sheet, but I'm not sure how to do that correctly in this set-up.
I already tried:
- the code with a single range without the i-loop: code works
- add ActiveSheet to the with-loop: With Activesheet.Range(DRng).cell: fail
- add different ways to refer to the range/sheet: fail
cell.select before with cell.interior
Sub SetTelSlot() Dim cell As Range Dim DRng(1 To 5) As Range Dim i As Long Set DRng(1) = Range("E7:AB33") Set DRng(2) = Range("E45:AB71") Set DRng(3) = Range("E82:AB108") Set DRng(4) = Range("E119:AB145") Set DRng(5) = Range("E156:AB182") For i = LBound(DRng) To UBound(DRng) For Each cell In DRng(i) If cell.Value = "1" Then With cell.Interior .Pattern = xlSolid '==>this is giving the error .PatternColorIndex = xlAutomatic .Color = RGB(0, 204, 153) .TintAndShade = 0 .PatternTintAndShade = 0 End With cell.Font.Bold = SetBold cell.Font.Color = vbBlack cell.Value = "T" End If Next cell Next i End Sub