hendrikbez

Board Regular
Joined
Dec 13, 2013
Messages
95
Office Version
  1. 2021
Platform
  1. Windows
I have this as a micro

Code:
Sub sort1()
'
' sort1 Macro
'

'
    Range("A4:F18").Select
    ActiveWorkbook.Worksheets("All").sort.SortFields.Clear
    ActiveWorkbook.Worksheets("All").sort.SortFields.Add Key:=Range("F4:F18"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("All").sort.SortFields.Add Key:=Range("A4:A18"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("All").sort
        .SetRange Range("A4:F18")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

But the problem is that every day the row can be more or less that what I have got here, how can I make it so that it will now at what row to stop
With a macro of vb.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hia
try this
Code:
Sub sort1()
'
' sort1 Macro
'
    Dim UsdRws As Long

    UsdRws = Range("A" & Rows.Count).End(xlUp).Row
    Range("A4:F" & UsdRws).Select
    ActiveWorkbook.Worksheets("All").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("All").Sort.SortFields.Add Key:=Range("F4:F" & UsdRws), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("All").Sort.SortFields.Add Key:=Range("A4:A" & UsdRws), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("All").Sort
        .SetRange Range("A4:F" & UsdRws)
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top