Rotating or cycling data

IcemaNZ

New Member
Joined
Aug 20, 2010
Messages
3
I have been searching and searching for a solution to this.

I need to make a row or column of data that cycles such as

The line is: 1 2 3 4 5 then when I trigger an event (date change) I want them to move across or down and the 5 moves back to the start.

So the second time the line reads: 5 1 2 3 4

A solution to this would be awesome because it takes forever to do manually.

Also can they be moved more than one cell eg. 3 cells (I.E. 1 2 3 4 5, then 3 4 5 1 2)


Cheers
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I've assumed that you have each of the numbers 1 to 5 in cells A2 to E2 and you have a header row above this with descriptions in A1 to E1. Try adding the following code to whatever event you have used.

Code:
Sub test123()
    Dim cell As Range
    Dim Temp(4) As Integer
 
    Range("A1").Select
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlToRight)).Select
 
    For Each cell In Selection
        Temp((cell.Column) Mod 5) = cell.Value
    Next cell
    For Each cell In Selection
        Cells(cell.Row + 1, cell.Column) = Temp(cell.Column - 1)
    Next cell
 
End Sub

If you want the figures to move across 3 spaces change the line

Code:
Temp((cell.Column) Mod 5) = cell.Value

to

Code:
Temp((cell.Column+2) Mod 5) = cell.Value

Note you only add 2 because the array Temp is zero based.
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,261
Members
448,558
Latest member
aivin

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