Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / October 2006

Tip: Looking for answers? Try searching our database.

to reverse a column

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rasoul Khoshravan - 19 Oct 2006 16:22 GMT
I have a column of data.
I want to reverse it. Is it possible?

as
ab
ad

change to
ad
ab
as
Gary L Brown - 19 Oct 2006 22:12 GMT
'/=================================================/
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,
Signature

Gary Brown
gary_brown@ge_NOSPAM.com
If this post was helpful, please click the ''Yes'' button next to ''Was this
Post Helpfull to you?''.

> I have a column of data.
> I want to reverse it. Is it possible?
[quoted text clipped - 7 lines]
> ab
> as
JBoulton - 19 Oct 2006 22:12 GMT
Make a "helper" column with 1,2,3... and then sort descending on that.

> I have a column of data.
> I want to reverse it. Is it possible?
[quoted text clipped - 7 lines]
> ab
> as
David Biddulph - 19 Oct 2006 22:21 GMT
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.
Signature

David Biddulph

>I have a column of data.
> I want to reverse it. Is it possible?
[quoted text clipped - 7 lines]
> ab
> as
Gord Dibben - 19 Oct 2006 23:25 GMT
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

>I have a column of data.
>I want to reverse it. Is it possible?
[quoted text clipped - 7 lines]
>ab
>as
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.