PDA

View Full Version : Solved: sort multiple rows



lolos
12-03-2007, 01:06 AM
i want to sort multiple rows, but seem to only be able to do one at a time. I know that to sort multiple columns, I can highlight as many columns as I want and then select A to Z. But this doesn't seem to be the case for sorting rows. In terms of sorting rows, the only thing I can seem to do is to go into Data-->Sort-->Options-->Select Left to Right. I can then sort a single row, and from this window it looks like a may (although haven't figured out how to get it to work) three rows, but I cannot tell how I might be able to sort more than three rows. For instance, suppose I have the following data

3, 2, 1
6, 5, 4
98, 97, 96
33, 32, 21

I want to be able to select all of these rows and quickly sort them as follows:

1, 2, 3
4, 5, 6
96, 97, 98
21, 32, 33

tHANKS IN ADVANCE

anandbohra
12-03-2007, 02:15 AM
whats the issue involved in your query.

I simply put the given data in excel sheet
& sorted it as left to right with row1
& I got the sorted data as u mentioned.

so where is the probelm:bug:

lolos
12-03-2007, 10:37 AM
i forget to mention at the same time! Not one by one!
let's say i have 200> rows so i would like to sort them form min to max but all together!
so...

mikerickson
12-03-2007, 11:02 AM
The option button in the normal SORT screen leads to a "sort horizontaly" option. Might this be of use to you?

anandbohra
12-03-2007, 09:52 PM
As I said earlier there is no need to do one by one for each row
say your data is located in Range A1:Z200 ok
select the selection
go to Data - sort
sort it from left to right
Bingo
u done it it will sort all data row by row from min to max.

Even at this solution if u r not satisfied pl upload your file without sorting & your desired output.
will try our best to provide acceptable solution.

(to upload the file under additional options - press button manage attachments)

RECrerar
12-04-2007, 03:09 AM
As I said earlier there is no need to do one by one for each row
say your data is located in Range A1:Z200 ok
select the selection
go to Data - sort
sort it from left to right
Bingo
u done it it will sort all data row by row from min to max.

Hi, you only got the situation that he wanted because of the form of the sample data he gave. If you have a look at the example values given, then sorting by row1 only will have all the values in the correct order


3, 2, 1
6, 5, 4
98, 97, 96
33, 32, 21



sort by row1 ascending would give:


1, 2, 3
4, 5, 6
96, 97, 98


However say the sample data was

6, 5, 4
97, 96, 98
32, 33, 31

The sort would give:

4, 5, 6
98, 96, 97
31, 33, 32

If I am correct in understanding what you need is a method to sort each row in accending order by it's row?

Currently I can't think of a quick way to do this, but just thought it would be worth pointing out why anandbohra's seemed to work on the sample data but wouldn't for the whole workbook

RECrerar
12-04-2007, 03:18 AM
Hey, I put together this bit of code that seems to work. It assumes that the data is in columns A to Z with no blank cells in Column A. I'm still learning Excel myself so it may not the that efficient, but if you've only got about 200 rows of data the eficiancy shouldn't be a problem

Sub Macro1()
Dim row As Integer
row = 1
Do Until Cells(row, 1).Value = ""
Range(Cells(row, 1), Cells(row, 24)).Select
Selection.Sort Key1:=Range((Cells(row, 1).Address)), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
row = row + 1
Range("A1").Select
Loop
End Sub

anandbohra
12-04-2007, 04:04 AM
sorry lolos
failed to understand your query

now i got the same & here is the solution

Sub sort_data_row_by_row()
Dim sortrange As Range
Dim sortcounter, startrow, endrow
Dim shtSheetToWork As Worksheet
Application.ScreenUpdating = False

Set shtSheetToWork = ActiveWorkbook.Worksheets("Sheet1") '<= Change to Suit
startrow = 2 '<= Change to Suit
endrow = shtSheetToWork.Cells(Rows.Count, 1).End(xlUp).Row

For sortcounter = startrow To endrow
Cells(startrow, "A").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:=Cells(startrow, "A"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
startrow = startrow + 1
Next sortcounter

Application.ScreenUpdating = True
End Sub