# Cycling through a numeric string

#### Atroxell

##### Active Member
HI,

I want to use the sequence "0123456789" to search a multiple lists of phone numbers.

After searching the list with the first number, I want to rotate the characters to read "1234567890" and search again.

After each search, I want to rotate the number sequence and search again. So the next iteration would be "2345678901", then "3456789012" and so on.

When one of the sequence is found, the phone number is deleted from the list.

This has to be done in VBA to compliment the other code I have written (none of which is relevant to this function, or I would post it.) I can wirte the find() part of the code, I just seem to be lost for writing the rotation of the numbers. I've looked all over, but I can't seem to find anything. Or maybe I just don't know what the search terms should be. I seem to remember that there is a mathematical name for this type of progression, but I can't remember it.

Can anyone help?

Thanks!

### Excel Facts

Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Here's one way to do it.

Code:
``````    [color=darkblue]Dim[/color] strTheNumber [color=darkblue]As[/color] [color=darkblue]String[/color]

strTheNumber = "1234567890"
strTheNumber = strTheNumber & strTheNumber

[color=darkblue]For[/color] i = 1 [color=darkblue]To[/color] 10
MsgBox Mid(strTheNumber, i, 10)
[color=darkblue]Next[/color] i``````

Just reset your variable to itself within a loop. Take a look at this snippet:

Code:
``````Sub test()

Dim x As String
Dim y As Long

x = "0123456789"
For y = 1 To 10
MsgBox (x)
x = Right(x, 9) & Left(x, 1)
Next y

End Sub``````

Thank you both!

I knew there was a reasonably simple solution, but my brain was flat lining. Must have been the long weekend. This will go to work almost immediately.

Thanks again!

Replies
6
Views
546
Replies
1
Views
107
Replies
3
Views
375
Replies
1
Views
400
Replies
2
Views
280

1,203,542
Messages
6,056,017
Members
444,840
Latest member
RazzelDazel

### 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.

### Which adblocker are you using?

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

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