Sort Code Modification

  • Thread starter Todd Huttenstine\(Remote\)
  • Start date
T

Todd Huttenstine\(Remote\)

I have the following working code to sort the range of data by the value in
combobox1.

Using the following code, what adjustments do I need to make to get it to
sort all the data by Ext?

Private Sub CommandButton2_Click()
'Sorts by the stat you select in the combobox.
'Sorts all data in the range A4:Z100

Dim Rng As Range, rng1 As Range
Dim res As Variant
Dim rng2 As Range
With Worksheets(1)
Set Rng = .Range("A4:Z100")
Set rng1 = .Range("A4:Z4")
End With
res = Application.Match(ComboBox1.Value, rng1, 0)
If Not IsError(res) Then
Set rng2 = rng1(1, res)
Rng.Sort Key1:=rng2, Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End If
Unload Me
End Sub



Thanx
Todd Huttenstine
 
B

Bill Manville

Todd said:
Using the following code, what adjustments do I need to make to get it to
sort all the data by Ext?

I assume "Ext" is the heading of a field somewhere in A4:Z4?

res = Application.Match("Ext", rng1, 0)

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup
 

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