how to sort in vba

Hi,

How can I sort my sheet by column A (excluding the header)? Ideally, i'd like to sort on the newly created sheet:
.Name = "Filtered from " & ws.Name


Thanks!

Sub FilterTwiceGLOBAL(ws As Worksheet)
Dim CoverageString As String
 CoverageString = Worksheets(1).Range("B3").Text & ""
'start filter code
Dim Rg As Range, rgCopy As Range
Dim rg2 As Range, rgCopy2 As Range
With ws
    Set Rg = .Range("B1").CurrentRegion
    'Set rgCopy = Rg.Offset(1, 0).Resize(Rg.Rows.Count - 1, Rg.Columns.Count)
    Set rgCopy = Rg
    icol = .Range("B:B").Column - Rg.Column + 1
    Rg.AutoFilter
    'Rg.AutoFilter field:=icol, Criteria1:=Array( _
    '"Robert Deutsch"), Operator:=xlFilterValues
    Rg.AutoFilter field:=icol, Criteria1:=Array( _
    CoverageString), Operator:=xlFilterValues
    rgCopy.Copy
 
    'create new sheet
    With Worksheets.Add(after:=Worksheets(Worksheets.Count))       'Destination worksheet
        .Cells(1, 1).PasteSpecial xlPasteValues
        Cells(1, 1).Select
        .Name = "Filtered from " & ws.Name
        .Columns.EntireColumn.AutoFit
        .Columns.EntireColumn.AutoFit
    End With
    Rg.AutoFilter
End With
End Sub

Open in new window

jfrank85Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wilder1626Commented:
Hi

Please take a look at what Martin Liss proposed on this below topic.

Pretty good VBA macro.
Let me know if this is what you are looking for.
Application of Range.Sort method (vba) dynamically - to a variable number of excel columns.
0
Rory ArchibaldCommented:
Small change from this:

    'create new sheet
    With Worksheets.Add(after:=Worksheets(Worksheets.Count))       'Destination worksheet
        .Cells(1, 1).PasteSpecial xlPasteValues
        Cells(1, 1).Select
        .Name = "Filtered from " & ws.Name
        .Columns.EntireColumn.AutoFit
        .Columns.EntireColumn.AutoFit
    End With

Open in new window


to this:

    'create new sheet
    With Worksheets.Add(after:=Worksheets(Worksheets.Count))       'Destination worksheet
        .Cells(1, 1).PasteSpecial xlPasteValues
        .Cells(1, 1).Select
        .Name = "Filtered from " & ws.Name
        .Columns.EntireColumn.AutoFit
        .Range("A:A").Sort Key1:=.cells(1), header:=xlYes
    End With

Open in new window


should do it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.