PC Review


Reply
Thread Tools Rate Thread

CODE rectification while sorting in descending order

 
 
Thulasiram
Guest
Posts: n/a
 
      27th Nov 2006
Hello all,

I have a a small set like this:

1.1 1 1 1 0 0 3
1.2 1 0 0 1 0 2
1.3 1 0 0 0 0 1
2.1 0 1 1 1 1 4
2.2 1 1 1 1 1 5

This set should be rearranged according to the descending order of the
last column. i.e. last column is sorted in descending order and its
corresponding rows are swapped accordingly.

End result would be:

2.2 1 1 1 1 1 5
2.1 0 1 1 1 1 4
1.1 1 1 1 0 0 3
1.2 1 0 0 1 0 2
1.3 1 0 0 0 0 1

I am using a code like this.

sub test()

Dim rng As Range

Set rng = Range("A2:G6") ' where A2 is 1 and G6 is 5
rng.Copy Destination:=Range("A10") ' copies the range to the A10 and
pastes the range

Range("O6").CurrentRegion.Sort Key1:=Range("O6"), Order1:=xlDescending

end sub

How to change the code to arrive at the end result as given in the
example above? Please help.

Thanks,
Thulasiram

 
Reply With Quote
 
 
 
 
Thulasiram
Guest
Posts: n/a
 
      27th Nov 2006
Sorry, the line in the sub in previous post should have been:

Range("G10").CurrentRegion.Sort Key1:=Range("G10"),
Order1:=xlDescending

This arranges the last column in descending order but not its
associated rows.

The full procedure is given again:

sub test()
Dim rng As Range

Set rng = Range("A2:G6")
rng.Copy Destination:=Range("A10")

Range("G10").CurrentRegion.Sort Key1:=Range("G10"),
Order1:=xlDescending
End Sub

Thanks,
Thulasiram

Thulasiram wrote:
> Hello all,
>
> I have a a small set like this:
>
> 1.1 1 1 1 0 0 3
> 1.2 1 0 0 1 0 2
> 1.3 1 0 0 0 0 1
> 2.1 0 1 1 1 1 4
> 2.2 1 1 1 1 1 5
>
> This set should be rearranged according to the descending order of the
> last column. i.e. last column is sorted in descending order and its
> corresponding rows are swapped accordingly.
>
> End result would be:
>
> 2.2 1 1 1 1 1 5
> 2.1 0 1 1 1 1 4
> 1.1 1 1 1 0 0 3
> 1.2 1 0 0 1 0 2
> 1.3 1 0 0 0 0 1
>
> I am using a code like this.
>
> sub test()
>
> Dim rng As Range
>
> Set rng = Range("A2:G6") ' where A2 is 1 and G6 is 5
> rng.Copy Destination:=Range("A10") ' copies the range to the A10 and
> pastes the range
>
> Range("O6").CurrentRegion.Sort Key1:=Range("O6"), Order1:=xlDescending
>
> end sub
>
> How to change the code to arrive at the end result as given in the
> example above? Please help.
>
> Thanks,
> Thulasiram


 
Reply With Quote
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      27th Nov 2006
Range("A2:G6").Sort Key1:=Range("G2"), Order1:=xlDescending
--
Best wishes,

Jim


"Thulasiram" wrote:

> Hello all,
>
> I have a a small set like this:
>
> 1.1 1 1 1 0 0 3
> 1.2 1 0 0 1 0 2
> 1.3 1 0 0 0 0 1
> 2.1 0 1 1 1 1 4
> 2.2 1 1 1 1 1 5
>
> This set should be rearranged according to the descending order of the
> last column. i.e. last column is sorted in descending order and its
> corresponding rows are swapped accordingly.
>
> End result would be:
>
> 2.2 1 1 1 1 1 5
> 2.1 0 1 1 1 1 4
> 1.1 1 1 1 0 0 3
> 1.2 1 0 0 1 0 2
> 1.3 1 0 0 0 0 1
>
> I am using a code like this.
>
> sub test()
>
> Dim rng As Range
>
> Set rng = Range("A2:G6") ' where A2 is 1 and G6 is 5
> rng.Copy Destination:=Range("A10") ' copies the range to the A10 and
> pastes the range
>
> Range("O6").CurrentRegion.Sort Key1:=Range("O6"), Order1:=xlDescending
>
> end sub
>
> How to change the code to arrive at the end result as given in the
> example above? Please help.
>
> Thanks,
> Thulasiram
>
>

 
Reply With Quote
 
Thulasiram
Guest
Posts: n/a
 
      27th Nov 2006
That was perfect Jim.

Thanks...

Jim Jackson wrote:
> Range("A2:G6").Sort Key1:=Range("G2"), Order1:=xlDescending
> --
> Best wishes,
>
> Jim
>
>
> "Thulasiram" wrote:
>
> > Hello all,
> >
> > I have a a small set like this:
> >
> > 1.1 1 1 1 0 0 3
> > 1.2 1 0 0 1 0 2
> > 1.3 1 0 0 0 0 1
> > 2.1 0 1 1 1 1 4
> > 2.2 1 1 1 1 1 5
> >
> > This set should be rearranged according to the descending order of the
> > last column. i.e. last column is sorted in descending order and its
> > corresponding rows are swapped accordingly.
> >
> > End result would be:
> >
> > 2.2 1 1 1 1 1 5
> > 2.1 0 1 1 1 1 4
> > 1.1 1 1 1 0 0 3
> > 1.2 1 0 0 1 0 2
> > 1.3 1 0 0 0 0 1
> >
> > I am using a code like this.
> >
> > sub test()
> >
> > Dim rng As Range
> >
> > Set rng = Range("A2:G6") ' where A2 is 1 and G6 is 5
> > rng.Copy Destination:=Range("A10") ' copies the range to the A10 and
> > pastes the range
> >
> > Range("O6").CurrentRegion.Sort Key1:=Range("O6"), Order1:=xlDescending
> >
> > end sub
> >
> > How to change the code to arrive at the end result as given in the
> > example above? Please help.
> >
> > Thanks,
> > Thulasiram
> >
> >


 
Reply With Quote
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      27th Nov 2006
Change "Range("G10")" to "Range("A2:G10")" and all the data will sort as
intended.
--
Best wishes,

Jim


"Thulasiram" wrote:

> Sorry, the line in the sub in previous post should have been:
>
> Range("G10").CurrentRegion.Sort Key1:=Range("G10"),
> Order1:=xlDescending
>
> This arranges the last column in descending order but not its
> associated rows.
>
> The full procedure is given again:
>
> sub test()
> Dim rng As Range
>
> Set rng = Range("A2:G6")
> rng.Copy Destination:=Range("A10")
>
> Range("G10").CurrentRegion.Sort Key1:=Range("G10"),
> Order1:=xlDescending
> End Sub
>
> Thanks,
> Thulasiram
>
> Thulasiram wrote:
> > Hello all,
> >
> > I have a a small set like this:
> >
> > 1.1 1 1 1 0 0 3
> > 1.2 1 0 0 1 0 2
> > 1.3 1 0 0 0 0 1
> > 2.1 0 1 1 1 1 4
> > 2.2 1 1 1 1 1 5
> >
> > This set should be rearranged according to the descending order of the
> > last column. i.e. last column is sorted in descending order and its
> > corresponding rows are swapped accordingly.
> >
> > End result would be:
> >
> > 2.2 1 1 1 1 1 5
> > 2.1 0 1 1 1 1 4
> > 1.1 1 1 1 0 0 3
> > 1.2 1 0 0 1 0 2
> > 1.3 1 0 0 0 0 1
> >
> > I am using a code like this.
> >
> > sub test()
> >
> > Dim rng As Range
> >
> > Set rng = Range("A2:G6") ' where A2 is 1 and G6 is 5
> > rng.Copy Destination:=Range("A10") ' copies the range to the A10 and
> > pastes the range
> >
> > Range("O6").CurrentRegion.Sort Key1:=Range("O6"), Order1:=xlDescending
> >
> > end sub
> >
> > How to change the code to arrive at the end result as given in the
> > example above? Please help.
> >
> > Thanks,
> > Thulasiram

>
>

 
Reply With Quote
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      27th Nov 2006
Glad I could help.
--
Best wishes,

Jim


"Thulasiram" wrote:

> That was perfect Jim.
>
> Thanks...
>
> Jim Jackson wrote:
> > Range("A2:G6").Sort Key1:=Range("G2"), Order1:=xlDescending
> > --
> > Best wishes,
> >
> > Jim
> >
> >
> > "Thulasiram" wrote:
> >
> > > Hello all,
> > >
> > > I have a a small set like this:
> > >
> > > 1.1 1 1 1 0 0 3
> > > 1.2 1 0 0 1 0 2
> > > 1.3 1 0 0 0 0 1
> > > 2.1 0 1 1 1 1 4
> > > 2.2 1 1 1 1 1 5
> > >
> > > This set should be rearranged according to the descending order of the
> > > last column. i.e. last column is sorted in descending order and its
> > > corresponding rows are swapped accordingly.
> > >
> > > End result would be:
> > >
> > > 2.2 1 1 1 1 1 5
> > > 2.1 0 1 1 1 1 4
> > > 1.1 1 1 1 0 0 3
> > > 1.2 1 0 0 1 0 2
> > > 1.3 1 0 0 0 0 1
> > >
> > > I am using a code like this.
> > >
> > > sub test()
> > >
> > > Dim rng As Range
> > >
> > > Set rng = Range("A2:G6") ' where A2 is 1 and G6 is 5
> > > rng.Copy Destination:=Range("A10") ' copies the range to the A10 and
> > > pastes the range
> > >
> > > Range("O6").CurrentRegion.Sort Key1:=Range("O6"), Order1:=xlDescending
> > >
> > > end sub
> > >
> > > How to change the code to arrive at the end result as given in the
> > > example above? Please help.
> > >
> > > Thanks,
> > > Thulasiram
> > >
> > >

>
>

 
Reply With Quote
 
Thulasiram
Guest
Posts: n/a
 
      27th Nov 2006
The modified code given in the second post solved the problem that I
faced (in my first post in this thread). I was able to rectify it. So,
got the solution!

Just wanted to post the update so that none ponders over the solved
issue.

Thanks,
Thulasiram

Thulasiram wrote:
> Sorry, the line in the sub in previous post should have been:
>
> Range("G10").CurrentRegion.Sort Key1:=Range("G10"),
> Order1:=xlDescending
>
> This arranges the last column in descending order but not its
> associated rows.
>
> The full procedure is given again:
>
> sub test()
> Dim rng As Range
>
> Set rng = Range("A2:G6")
> rng.Copy Destination:=Range("A10")
>
> Range("G10").CurrentRegion.Sort Key1:=Range("G10"),
> Order1:=xlDescending
> End Sub
>
> Thanks,
> Thulasiram
>
> Thulasiram wrote:
> > Hello all,
> >
> > I have a a small set like this:
> >
> > 1.1 1 1 1 0 0 3
> > 1.2 1 0 0 1 0 2
> > 1.3 1 0 0 0 0 1
> > 2.1 0 1 1 1 1 4
> > 2.2 1 1 1 1 1 5
> >
> > This set should be rearranged according to the descending order of the
> > last column. i.e. last column is sorted in descending order and its
> > corresponding rows are swapped accordingly.
> >
> > End result would be:
> >
> > 2.2 1 1 1 1 1 5
> > 2.1 0 1 1 1 1 4
> > 1.1 1 1 1 0 0 3
> > 1.2 1 0 0 1 0 2
> > 1.3 1 0 0 0 0 1
> >
> > I am using a code like this.
> >
> > sub test()
> >
> > Dim rng As Range
> >
> > Set rng = Range("A2:G6") ' where A2 is 1 and G6 is 5
> > rng.Copy Destination:=Range("A10") ' copies the range to the A10 and
> > pastes the range
> >
> > Range("O6").CurrentRegion.Sort Key1:=Range("O6"), Order1:=xlDescending
> >
> > end sub
> >
> > How to change the code to arrive at the end result as given in the
> > example above? Please help.
> >
> > Thanks,
> > Thulasiram


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting the data in descending order Excelorator Microsoft Excel Programming 3 2nd Apr 2010 12:11 PM
Sorting a column with numbers into descending order =?Utf-8?B?d2FyZGxlODY=?= Microsoft Excel Programming 2 4th Oct 2007 06:58 PM
Sorting Charts By Descending Order Pete Microsoft Access Getting Started 0 11th May 2007 03:53 AM
sorting a datagrid in descending order =?Utf-8?B?TmV3Ymll?= Microsoft C# .NET 4 7th Jul 2005 08:54 PM
Problem with sorting listview in descending order James Zhuo Microsoft Dot NET Framework Forms 2 1st Dec 2003 10:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:19 AM.