Macro for Sorting Varied Ranges

defls

New Member
Joined
Sep 29, 2017
Messages
1
I am looking to record or create a macro where i can sort varied ranges (by rows & columns) of data without sorting the headers & footers with the data. I have tried recording using CTRL+* and CTRL+{ and other various shortcuts, but have not come to a solution. This is a report that we make 300+ times a year, so I am trying to automate it as much as possible.

Thank you for any help.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
A bit hard to tell exactly what you want here as you give very little info on the ranges and no info on the sheet name or column to sort by so the below sorts on Worksheets("Sheet3") with Column C as the column it is sorting by, ignoring the first and last row.

Code:
Sub SortRange2()
    Dim LstRw As Long, LstCol As Long
    LstCol = Worksheets("Sheet3").Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
    LstRw = Worksheets("Sheet3").Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row - 1

    With Worksheets("Sheet3")
        .Range(.Cells(1, 1), .Cells(LstRw, LstCol)).Sort _
                Key1:=Worksheets("Sheet3").Columns("C"), Header:=xlYes
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,823
Members
449,470
Latest member
Subhash Chand

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