reversing the order of 2 columns

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
Is there any way/trick to reverse a table without using sorting? Here is my table

From

averagegrade
0f
50c
60b
80a

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

To

averagegrade
80a
60b
50c
0f

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

Thank you very much.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
One way, copied across and down

Excel Workbook
ABCDE
1averagegrade
20f80a
350c60b
460b50c
580a0f
Reverse
 
Upvote 0
VBA?
Code:
Sub revers()
    Dim a As Variant
    Dim i, j, lr, t As Integer
    lr = Cells(Rows.Count, 1).End(xlUp).Row - 1
    a = Cells(2, 1).Resize(lr, 2)
    ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
    t = 1
    For i = lr To 1 Step -1
        For j = 1 To 2
            b(t, j) = a(i, j)
        Next
        t = t + 1
    Next
    Cells(2, 3).Resize(lr, 2) = b
End Sub
 
Last edited:
Upvote 0
Thanks all for the help. Not prohibited but I thought there is another way I do not know off. Thanks all once again
You're welcome.

.. and of course if the data started out in a jumbled order then sorting wouldn't reverse the table anyway. :)
 
Last edited:
Upvote 0
If you are interested, here is a vba way to reverse a table (but keep the headings) without looping through the rows and columns.

Rich (BB code):
Sub Reverse_Table()
  Dim rws As Long, cols As Long
  Dim vRws As Variant, vCols As Variant
  
  With Range("A1").CurrentRegion
    rws = .Rows.Count
    cols = .Columns.Count
    vRws = Application.Transpose(Split("1 " & Join(Application.Transpose(Evaluate(rws + 1 & "- row(1:" & rws - 1 & ")")))))
    vCols = Application.Transpose(Evaluate("row(1:" & cols & ")"))
    .Offset(, cols + 1).Value = Application.Index(.Value, vRws, vCols)
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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