to reverse a column

R

Rasoul Khoshravan

I have a column of data.
I want to reverse it. Is it possible?

as
ab
ad

change to
ad
ab
as
 
G

Gary L Brown

'/=================================================/
Sub FlipIt()
'reverse order of a selection
' 1st cell is last and last is first, ett
'
Dim aryCollection()
Dim LngCount As Long
Dim lngCellCount As Long
Dim rng As Range

Set rng = Application.InputBox(Prompt:="Select Range to be Searched: ", _
Title:="Range Selection...", _
Default:=Application.Selection.Address, Type:=8)

If Len(rng.Address) = 0 Then
MsgBox "No Cells were selected." & vbLf & vbLf & _
"Process Aborted.....", vbExclamation + vbOKOnly, "WARNING....."
Exit Sub
End If

rng.Select

'check for multiple range selections
If Selection.Areas.Count > 1 Then
MsgBox "Multiple Range selections are not supported.", _
vbExclamation + vbOKOnly, "Warning..."
End If

If Selection.Cells.Count = 1 Then
MsgBox "You have not selected a range of cells.", _
vbExclamation + vbOKOnly, "Warning..."
Exit Sub
End If

lngCellCount = Selection.Cells.Count

'redim array
ReDim aryCollection(1 To lngCellCount)

'populate array
For LngCount = 1 To lngCellCount
aryCollection(LngCount) = Selection.Cells(LngCount).value
Next LngCount

'reverse order of cells
For LngCount = lngCellCount To 1 Step -1
Selection.Cells(lngCellCount - LngCount + 1).value = _
aryCollection(LngCount)
Next LngCount


End Sub
'/=================================================/

HTH,
 
D

David Biddulph

The easiest way is probably to add a helper column alongside with numbers
from 1 to N.
Select the two columns, & sort by your second column in descending order,
then you can delete your helper column.
 
G

Gord Dibben

In an adjacent column enter the numbers 1 to whatever.

Select both columns and sort on that column in descending order.


Gord Dibben MS Excel MVP
 
Top