79834749

Date: 2025-12-01 11:33:41
Score: 0.5
Natty:
Report link

I hope you are well.

You might need an error check in there to find the last non empty row. Code snippet below on how I would approach this. Your code would also most likely throw an error if there is only 1 row of data hence another check for lrow < 2.

Thanks!

Sub SortByCol5()

Dim ws As Worksheet
Dim lrow As Long
Dim sortRange As Range

Set ws = ThisWorkbook.Worksheets("Sheet2")

'Find last used row in sheet'
lrow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row

'Error check for only 1 row'

If lrow < 2 Then Exit Sub

Set sortRange = ws.Range("A2:E" & lrow)

sortRange.Sort _
    Key1:=ws.Range("E2:E" & lrow), _
    Order1:=xlAscending, _
    Header:=xlNo

End Sub
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Muhammad Fahad