Sub SPIRALCELLS()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim r As Range: Set r = Range("A1:E5")
Dim mCnt As Integer: mCnt = 0
Dim Pos As Integer: Pos = 1
Dim Limit As Integer: Limit = (r.Rows.Count * 2) - 1
Dim oSet As Integer: oSet = ((r.Rows.Count + 1) / 2) - 1
Dim sCel As Range: Set sCel = r.Cells(1, 1).Offset(oSet, oSet)
Dim YB As Boolean: YB = True
With r
With .Borders
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
.RowHeight = 24.75
.ColumnWidth = 5
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
For i = 1 To Limit
If (i Mod 2 = 1 And i <> Limit) Then mCnt = mCnt + 1
Select Case i Mod 4
Case 0
ListCells sCel, mCnt, True, True, YB, Pos
Case 1
ListCells sCel, mCnt, False, False, YB, Pos
Case 2
ListCells sCel, mCnt, False, True, YB, Pos
Case 3
ListCells sCel, mCnt, True, False, YB, Pos
End Select
Next i
sCel.Value = Pos
sCel.Interior.ColorIndex = 8
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sub ListCells(sCel As Range, mCnt As Integer, Sign As Boolean, XY As Boolean, YB As Boolean, Pos As Integer)
For i = 1 To mCnt
sCel.Value = Pos
If Pos < 10 Then
Select Case Pos Mod 2
Case 0
sCel.Interior.ColorIndex = 6
Case 1
sCel.Interior.ColorIndex = 8
End Select
Else
Select Case Pos Mod 2
Case 0
sCel.Interior.ColorIndex = 2
Case 1
sCel.Interior.ColorIndex = IIf(YB, 6, 8)
YB = Not YB
End Select
End If
If XY Then
If Sign Then Set sCel = sCel.Offset(1) Else Set sCel = sCel.Offset(-1)
Else
If Sign Then Set sCel = sCel.Offset(, 1) Else Set sCel = sCel.Offset(, -1)
End If
Pos = Pos + 1
Next i
End Sub