VBA Sort

Littlemalky

Board Regular
Joined
Jan 14, 2011
Messages
223
I need to sort this group of data. The name of the worksheet is "detail w add"; the top line is the header, naturally, and the columns go from A:V. I need to sort relative to column "V" in Ascending order. The caviot is that this data is ever changing and there is a break in rows that I've created so I can sort just the top portion of the data. I found code that looks like it would work, but I'm getting the error, "Compile error: Expected: list Seperator or )". Is this code wrong?

Code:
Private Sub SecondSort()
 Dim LastRow As Integer   'This is the LAST Non Empty Row
    LastRow = ActiveSheet.UsedRange.Row - 1 + _
            ActiveSheet.UsedRange.Rows.Count
    Worksheets("detail w add").Range("A2:V" & LastRow & ").Sort Key:=Worksheets("detail w add").Columns("V"), Order1:=xlAscending
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You have an orphan quote. Try this:
Code:
Private Sub SecondSort()
    Dim lRow As Long
 
    With Worksheets("detail w add")
        lRow = .UsedRange.Row + .UsedRange.Rows.Count - 1
        .Range("A1", Cells(lRow, "V")).Sort _
                Key1:=.Columns("V"), _
                Order1:=xlAscending, _
                Header:=xlYes
    End With
End Sub
 
Upvote 0
You're welcome, glad it worked for you.
 
Upvote 0
You know what, it's working for the most part except for the very first row it doesn't seem to be including into the sort. In S2, it's stating a "4", where it should be stating a "0" because that's the lowest number in the column. This is my entire line of code in the macro, did I denote something wrong?
Code:
Worksheets("detail w add").Range("S2").Select
    Range("S2").Formula = "=NETWORKDAYS(Q2,R2)-1"
    Selection.NumberFormat = "#,##0"
    With ws
        .Range("S2").AutoFill Destination:=.Range(.Cells(2, 19), .Cells(Cells(Rows.Count, 20).End(xlUp).Row, 19))
    End With
    Worksheets("Summary").Activate
    Range("B50").Formula = "=ROUND(AVERAGE('detail w add'!S:S),0)" 'Takes average
    Worksheets("Summary").Range("B50").Copy
    Worksheets("Summary").Range("B50").PasteSpecial xlPasteValues
    Worksheets("detail w add").Activate
    With Worksheets("detail w add")
        lRow = .UsedRange.Row + .UsedRange.Rows.Count - 1
        .Range("A1", Cells(lRow, "V")).Sort _
                Key1:=.Columns("S"), _
                Order1:=xlAscending, _
                Header:=xlYes
    End With
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,910
Members
452,949
Latest member
beartooth91

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