Sort the Active page

Seansr

New Member
Joined
Jan 31, 2011
Messages
8
I have a macro that copies data from one spreadsheet and creates a new sheet based on a name entered in a input box

The last bit of the macro I need to do is to Filter the newly created active sheet by Column U - Acending
:confused:
But I am getting Run Time errors



ActiveSheets.Select
Range("B1").Activate
ActiveSheet.Sort.SortFields.Clear
ActiveSheet.Sort.SortFields.Range ("A1:BV18"), SortOn:=xlSortOnValues, Order:=Ascending, DataOption:=xlSortNormal
With ActiveSheets.Select
.SetRange Range("A1:BV18")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try

Rich (BB code):
ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Range ("A1:BV18"), SortOn:=xlSortOnValues, Order:=Ascending, DataOption:=xlSortNormal
    With ActiveSheet
    .SetRange Range("A1:BV18")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply         
End With
 
Upvote 0
That has returned a

Run-time Error '438':
Object doesn't support this property or method

Complaining about

ActiveSheet.Sort.SortFields.Range ("A1:BV18"), SortOn:=xlSortOnValues, Order:=Ascending, DataOption:=xlSortNormal

Regards

Sean
 
Upvote 0
Try

Code:
ActiveSheet.Sort.SortFields.Add Key:=Range("A1:BV18"), SortOn:=xlSortOnValues, Order:=Ascending, DataOption:=xlSortNormal
 
Upvote 0
Is the sheet protected?

Have you tried recording a macro whilst doing this manually?
 
Upvote 0
The sheet is not protected

I have tried to record the macro and it's where I took the main part of my macro from

But when I record the macro it adds in the name of the sheet, but as this can be different each time I wanted it to be the active sheet it was still had focus on

I have allocated a button with the macro assigned on my master worksheet to make things easy for the operators to use

Sean
 
Upvote 0
This works for me - note that I used a smaller range to test

Code:
Sub Macro2()
'
' Macro2 Macro
'

'
    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=Range("B2:B13") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveSheet.Sort
        .SetRange Range("A1:C13")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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