Macro to sort Data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,601
Office Version
  1. 2021
Platform
  1. Windows
I have written code to sort data in Col F. The macro works well, except if therte is only one row of data. I would like the code amended, so that if there is only 1 row of data from row 6 onwards (A6:F6), the macro must exit

Your assistance will be most appreciated


Sub Sort_Ageing()
Dim Lr As Long
Lr = Cells(Rows.Count, "F").End(xlUp).Row
With Range("F6:F" & Lr)
.Sort Key1:=Range("F6"), Order1:=xlAscending
End With
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
howard,


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Code:
Sub Sort_Ageing()
Dim Lr As Long
Lr = Cells(Rows.Count, "F").End(xlUp).Row
If Lr > 7 Then
  With Range("F6:F" & Lr)
    .Sort Key1:=Range("F6"), Order1:=xlAscending
  End With
End If
End Sub
 
Upvote 0
Hi Guys

Thanks for the help,much appreciated
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,510
Members
452,918
Latest member
Davion615

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