Determining if data is sorted in descending order

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I capture the pre-sorted data to an array, then show a form to ask user to
sort descending; In the form, user clicks button after sorting and I want to
compare pre sorted to post sorted values; can't pass the presorted array to
the buttons click event. Ideas for a workaround? TY
 
Not sure if I understand correctly...

Code
-------------------

Private Sub CommandButton1_Click()
Dim a, i As long, myRange
Set myRange = Range("a1:a100")
If vbYes = MsgBox("Sort Descending Order?",vbYesNo) Then
With myRange
a = .Value
.Sort key1:= .Cells(1,1), order1:= xlDescending, header:= xlNo
For i = 1 To .Rows.Count
If .Cells(i,1) <> a(i, 1) Then
MsgBox "Not Sorted in Descengind Order"
.Value = a
Exit Sub
End If
Next
End With
End If
MsgBox "Sorted successfully"
End Su
 

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

Back
Top