rjacmuto32
Board Regular
- Joined
- Jul 14, 2004
- Messages
- 98
I have a set of data that I want to put a macro to Sort the data by 2 columns. The twist is each time I will run the macro, my data will have a different ending Column # and Row # so I can't do a defined Ranger. I selected my starting cell A2 in the code below, then put the XL Right and Down to select all the data before it's sorted. Below that is my Sorting Code for the 2 columns. what I noticed is in the Sort it has =Range("E3:E8"). How do you fix that to be eqaul the range I'm selecting in the first part of the code? Cell E3 contains the first value to be sorted (E2 is the header). How do you make it go to the bottom of the range and not stop at row 8?
THanks,
--Robert
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("E3:E8"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("F3:F8"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
THanks,
--Robert
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("E3:E8"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("F3:F8"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal