November 9, 2012
Trusted Members
October 18, 2018
Trusted Members
October 18, 2018
Moderators
January 31, 2022
Trusted Members
October 17, 2018
November 9, 2012
I find the way by myself!
I change it a little, it works. you can see that:
Sub Spiral_new()
Dim userinput As Long, n As Long, i As Long, j As Long, rngAddr As Range
userinput = InputBox("How many cells for Spiralling?")
n = 1: j = 0: i = 1
Set rngAddr = Cells(10, 10)
Do Until n > userinput
Do Until j >= i
If n <= userinput Then
Set rngAddr = rngAddr.Offset(0, 1)
rngAddr.Value = n
j = j + 1
n = n + 1
Else
Exit Sub
End If
Loop
j = 1
Do Until j >= i
If n <= userinput Then
Set rngAddr = rngAddr.Offset(-1, 0)
rngAddr.Value = n
j = j + 1
n = n + 1
Else
Exit Sub
End If
Loop
i = i + 1
j = 1
Do Until j >= i
If n <= userinput Then
Set rngAddr = rngAddr.Offset(0, -1)
rngAddr.Value = n
j = j + 1
n = n + 1
Else
Exit Sub
End If
Loop
j = 1
Do Until j >= i
If n <= userinput Then
Set rngAddr = rngAddr.Offset(1, 0)
rngAddr.Value = n
j = j + 1
n = n + 1
Else
Exit Sub
End If
Loop
i = i + 1
j = 1
Loop
Set rngAddr = Nothing
End Sub
Answers Post
1 Guest(s)