Weird sorting results

J

J Streger

I have the following procedure on a worksheet. It's intention is to sort the
rows on the sheet by a value in the score column. The rows are set up as
outline rows, so you have a high level row and several rows underneath. The
outline column is just a means to keep the low level lines together with the
high level they belong to.

When I run the procedure, instead of ordering the rows by score, it orders
them by outline. I can manually sort them back to score, but when run
programatically it completely ignores sorting by score. The scores are all
different numbers and you can see the values in no particular order after the
sort. I ensures the area is correct and it seems to run the sort, but not
correctly. Any idea why this may be? Thanks!

Private Sub cmdScoreSort_Click()
'sort Sheet
Dim sAddress As String

DisableScreenUpdates

sAddress = Selection.Address

'get rid of outline
Me.Cells.ClearOutline

'Sort first by score, then by outline
Me.Range(Me.Cells(TOP_ROW - 1, 1), Me.Cells(Me.Cells(Rows.Count,
RPT_SCORE_COL).End(xlUp).Row, RPT_OUTLINE_COL)).Sort _
key1:=Me.Cells(TOP_ROW - 1, RPT_SCORE_COL), order1:=xlDescending, _
key2:=Me.Cells(TOP_ROW - 1, RPT_OUTLINE_COL), order2:=xlAscending,
header:=xlYes

'Re-add the outline to each line
For inx = TOP_ROW To Me.Cells(Rows.Count, RPT_SCORE_COL).End(xlUp).Row
If Me.Cells(inx, RPT_PC_COL) = "" Then
Me.Rows(inx).OutlineLevel = 2
End If

Next

Me.Outline.ShowLevels 1

Me.Range(sAddress).Select

EnableScreenUpdates

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top