ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sort Code Modification (https://www.excelbanter.com/excel-programming/283737-sort-code-modification.html)

Todd Huttenstine\(Remote\)

Sort Code Modification
 
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



Bill Manville

Sort Code Modification
 
Todd Huttenstine(Remote) wrote:
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



All times are GMT +1. The time now is 11:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com