Create a Spiral Number System

birko61

New Member
Joined
Jun 20, 2004
Messages
21
Hi,
can someone please help me create some VB code to do the following....

I want to create a circular number system, where 1 is in the middle of the page then each cell increases by 1 in like the following, then stopping at 1000.

13 14 15 16 17
12 03 04 05 18
11 02 01 06 19
10 09 08 07 20
25 24 23 22 21

Thanks in advance.
Birko
 
Last edited:
See if this is any use.

VBA Code:
Sub Spiral()
   Dim Pos As Range
   Dim i As Long, rOffset As Long, cOffset As Long
   
   Application.ScreenUpdating = False
   Set Pos = Range("Z26") '<-- Starting cell - adjust to suit
   Pos.Value = 1
   Set Pos = Pos.Offset(0, -1)
   For i = 2 To 1000
      Pos.Value = i
      If Pos.Offset(, -1).Value = "" And Pos.Offset(-1).Value <> "" Then
         rOffset = 0: cOffset = -1
      ElseIf Pos.Offset(, -1).Value <> "" And Pos.Offset(1).Value = "" Then
         rOffset = 1: cOffset = 0
      ElseIf Pos.Offset(1).Value <> "" And Pos.Offset(, 1).Value = "" Then
         rOffset = 0: cOffset = 1
      ElseIf Pos.Offset(, 1).Value <> "" And Pos.Offset(-1).Value = "" Then
         rOffset = -1: cOffset = 0
      End If
      Set Pos = Pos.Offset(rOffset, cOffset)
   Next i
   Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:
Upvote 0
How to use this code in excel total beginner
when i copy to excel module i can't make it to work
 
Upvote 0
i want to make it Functions in circles like the numbers above and be able to change it
 
Upvote 0
Have another go, I've removed the formatting from the post
 
Upvote 0
No idea. I would suggest that you start a thread of your own, giving exact details of what you are trying to achieve.
 
Upvote 0

Forum statistics

Threads
1,226,874
Messages
6,193,451
Members
453,800
Latest member
dmwass57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top