Content Rotation from column to column

rize1159

Board Regular
Joined
Jan 8, 2011
Messages
51
I have a work sheet containing first name in A1 and last name in AA1. Now I want to arrange the these words in a specific order by of column differences. Let suppose A1=X,B1=Y,C1=Z, D1=W, E1=Q
we will prepare second row by keeping first letter constant at its place and replacing the others by constant column difference Like:

A1=X,B1=Z,C1=Q, D1=Y, E1=W

first letter is kept constant and second comes from third column of last row. this process will continue till all 28 names are formed in the same way. the column difference will be 1 to 28.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi rize,

I think this time, the effort has provided good results, below you can see the modified macro.
According to my tests, it works with both, even and odd number of columns, but especially it
works with 28 columns which is what you really need.
Excel Workbook
ABCDEFGHIJKLM
1abcdefghijkl0
2acegikbdfhjl0
3adgjbehkcfil0
4aeibfjcgkdhl0
5afkdibglejch0
6agbhcidjekfl0
7ahcjelgbidkf0
8aiebjfckgdlh0
9ajgdbkheclif0
10akigecbljhfd0
11alkjihgfedcb0
12abcdefghijkl0
The following example (12 columns
#VALUE!

1) In A1 type
Excel Workbook
CellFormula
B1=CHAR(CODE(LEFT(A1,1))+1)
"a", in B1 type the formula below and copy to the right up to L1;
#VALUE!

2-) Run the macro and wait the result;
3-) In M1 copy the formula below and copy down
;
4-) If all are zeros, all is ok :biggrin:.
Cell Formulas
RangeFormula
M1=SUM(IF(FREQUENCY(MATCH(A1:L1,A1:L1,0),MATCH(A1:L1,A1:L1,0))>0,0))

The macro is:
Code:
[COLOR=Navy]Sub [/COLOR]Rotate_Columns()
[COLOR=Green]'César C, 04/May/2011
'Macro to rotate even and odd number of colums in specific order

[COLOR=Black][COLOR=Navy]Dim [COLOR=Black]FirstRowCols() As Variant[/COLOR]
Dim [COLOR=Black]Lc As Integer, Indx As Integer, Rep As Integer[/COLOR]
Dim [COLOR=Black]m As Integer, i As Integer, j As Integer, p As Integer[/COLOR][/COLOR][/COLOR][/COLOR]

Application.ScreenUpdating = [COLOR=Navy]False[/COLOR]

Lc = Range("A1").End(xlToRight).Column [COLOR=Green]'Last column number[/COLOR]
[COLOR=Navy]ReDim [/COLOR]FirstRowCols(1 To Lc ^ 2)

For m = 0 To Lc - 1 [COLOR=Green]'Loading array with repeated values[/COLOR]
    For n = 1 To Lc
        FirstRowCols(n + m * Lc) = Cells(1, n)
    Next
Next

For i = 2 To Lc [COLOR=Green]'Iterate from column 2 up to the last one[/COLOR]
    If i< Lc Then
      Indx = 1 + i
      Cells(i, 1) = Cells(1, 1)
        For j = 2 To Lc
            Rep = Application.WorksheetFunction.CountIf(Range(Cells(i, 1), _
            Cells(i, Lc)), FirstRowCols(Indx))
            If Rep = 0 Then
               Cells(i, j) = FirstRowCols(Indx)
            Else
               Indx = Indx + 1
               Cells(i, j) = FirstRowCols(Indx)
            End If
        Indx = Indx + i
        Next j
    Else
            For p = 1 To Lc
                Cells(i, p) = FirstRowCols(p)
            Next p
    End If
Next i
Application.ScreenUpdating = [COLOR=Navy]True[/COLOR]
[COLOR=Navy]End Sub[/COLOR]
Below is the result for 28 columns.

28_Columns_Rotation.jpg


Hope this helps,

Regards
 
Upvote 0
Macro has done its job, I checked there were no repeats. However formula for cross verification didn't worked on real data as data was for names not for letters. Butt don't worry. Its good for me.

Thank you buddy
God bless you.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

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