sort of my cells in a workpage

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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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