Sub Test1()
Application.ScreenUpdating = False
Cells.ClearContents
Calc_Spiral "J19", 1, 240, 1, 2, True, True
Columns("A:K").Delete Shift:=xlToLeft
End Sub
Sub Calc_Spiral(strStartingCell$, iStartingNumber%, iMaxCount%, iStep%, iStartingDirection%, bClockwise As Boolean, bSecond As Boolean)
Rem https://ask.libreoffice.org/t/how-to-program-draw-a-square-spiral/29883
Rem <strStartingCell> : A single cell address, e.g. "H12" representing the center of the spiral.
Rem <iStartingNumber> : Integer to be displayed inside the starting cell; Incremented by 1 for each following cell.
Rem <iMaxCount> : The total amount of cells to be drawn in the spiral;
Rem NB. Cells that fall outside of the Sheet''s edges are not counted in the total amount.
Rem <iStep> : Integer increase of the armlength after each turn in the spiral.
Rem <iStartingDirection> : Determines the direction of the second cell to be drawn, relative to the starting cell.
Rem 0=RIGHT ; 1=UP ; 2=LEFT ; 3=DOWN.
Rem <bClockwise> : Boolean indicating whether the spiral goes clockwise ( <True> ) or counter-clockwise ( <False> ).
Rem <bSecond> : If <True> , the armlength increases only every second turn instead of every turn.
Rem Example call : Calc_Spiral( "H12", 1, 100, 1, 2, True, True )
'On Error Resume Next
Dim oSheet As Worksheet, oCell As Range, iColumn%, iRow%, m%, iCount%, iDirection%, iCurrentStep%, iCurrentPos%, iArmCount%
Set oSheet = ActiveSheet
Set oCell = oSheet.Range(strStartingCell)
iRow = oCell.Row
iColumn = oCell.Column
iCount = 0
iDirection = iStartingDirection
iCurrentStep = iStep
iCurrentPos = 0
' If iCurrentStep = 0 Then iCurrentStep = 1 '
m = 1
If bClockwise Then m = 3
Do While iCount < iMaxCount
oCell.Value = iStartingNumber + iCount 'REM Display the index number inside the cell.
If iCurrentPos = iCurrentStep Then 'Rem End of Arm reached:
iArmCount = iArmCount + 1
iDirection = (iDirection + m) Mod 4 'REM Compute the Next direction.
iCurrentPos = 0
If Not bSecond Or (iCount > 0 And iArmCount Mod 2 = 0) Then iCurrentStep = iCurrentStep + iStep
End If
Select Case iDirection
Case 0 'REM Right
iColumn = iColumn + 1
Case 1 'REM Up
iRow = iRow - 1
Case 2 'REM Left
iColumn = iColumn - 1
Case 3 'REM Down
iRow = iRow + 1
End Select
Set oCell = Cells(iColumn, iRow) 'REM Go towards the Next Cell.
iCurrentPos = iCurrentPos + 1
iCount = iCount + 1
Loop
End Sub