ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how can I sort on the column selected by the user? (https://www.excelbanter.com/excel-programming/340859-how-can-i-sort-column-selected-user.html)

-JEFF-[_2_]

how can I sort on the column selected by the user?
 
I query the user via a userform to select the heading (column) they want to
sort on. The userform returns a column. I need to sort everything from row
11 down based on the column selected. I have no problem selecting the cells
from A11 to the end, but I don't know the code to perform the sort. Will
somebody please help?

this is my code for the selecting the range that needs to be sorted
x = Range("A" & Rows.Count).End(xlUp).Row
Range("A11", "AA" & x).Select

If the user selects "ORDER NUMBER" from the user form (column y), how do I
sort my range on column y?
-JEFF-


Jim Rech

how can I sort on the column selected by the user?
 
This is a simple example that may help you.

Sub a()
Dim Key As String
Dim SortCell As Range
Key = "HeaderX"
Set SortCell = Range("A1:E1").Find(Key)
Range("A1:E8").Sort Key1:=SortCell, Header:=xlYes
End Sub

Here I have a small database in the range A1 to E8. Row 1 has the
column/field headers and I know that the field I want to sort by is headed
by "HeaderX". First I find the cell containing HeaderX and set the range
variable SortCell to it. Then I use that to set the first sort key in doing
the sort.

--
Jim
"-JEFF-" wrote in message
...
|I query the user via a userform to select the heading (column) they want to
| sort on. The userform returns a column. I need to sort everything from
row
| 11 down based on the column selected. I have no problem selecting the
cells
| from A11 to the end, but I don't know the code to perform the sort. Will
| somebody please help?
|
| this is my code for the selecting the range that needs to be sorted
| x = Range("A" & Rows.Count).End(xlUp).Row
| Range("A11", "AA" & x).Select
|
| If the user selects "ORDER NUMBER" from the user form (column y), how do I
| sort my range on column y?
| -JEFF-
|




All times are GMT +1. The time now is 01:30 AM.

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