Finding the last row to sort data

DrH100

Board Regular
Joined
Dec 30, 2011
Messages
78
I have the code below which was working fine

HTML:
Application.ScreenUpdating = False
    Range("A12:BD30").Select
    Range("BD30").Activate
    ActiveWorkbook.Worksheets("Employer Database").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Employer Database").Sort.SortFields.Add Key:=Range _
        ("B12:B30"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Employer Database").Sort
        .SetRange Range("A12:BD30")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("B12").Select
    
    Application.ScreenUpdating = True
End Sub

until i realised that the list of items is going to be longer that the current range but I don't know how big it might get.

Is there an easy way to amend the code to identify that last row with something in column A and then select the range from A12 to BD (whatever the last row is).

I've had a go with a few things I have found on the internet but don't really know what I am doing.

Thanks in advance for any help
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try:
Code:
Sub Macro1()

    Dim LR As Long
    
    Application.ScreenUpdating = False
    
    With Sheets("Employer Database")
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        If LR < 13 Then LR = 13
        .Range("A12:BD" & LR).Sort key1:=.Range("B12"), order1:=xlDescending, Header:=xlGuess
    End With
            
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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