Have this excel sheet and I need to sort all columns based of on data in Column H
• Column H are dates
• Ask the user to select the range
• Once selected, sort all data based on the values in column H in newest to oldest
I tried the following :
Sub qwerty()
Dim r As Range
Dim v As String
Dim x As String
Set r = Application.InputBox(Prompt:="Please Select Range", Title:="Range Select", Type:=8)
r.Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=r _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
Dim rr As Range
rr = Range("I2").End(xlDown)
' ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("I2:I100") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A2:I2.End(xlDown)")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Problem I encountered:
- Unable to select all the rows and columns – I think I am unable to tell it which is the LAST ROW that needs to be selected
Another thing I tried doing is:- Record the macro and go to DATA>Sort and select the columns and sort them from newest to oldest.
This gives the output but :
• It sorts row 1 too
• The selection has to be a user input using input box
FILE ATTACHED:
Thanks,
xlmxm.xlsm
Bookmarks