Sort VBA Code

matthew_ong12

New Member
Joined
Aug 15, 2018
Messages
18
Hi Mr Excel, would like to ask for your inputs on how to make this code work. I'm encountering an error when running it.

Code:
With ActiveWorkbook.Worksheets("Data Analysis").Sort
.SetRange Range("o3:eek:289")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Notes:
The "Data Analysis" is where the numbers are found and is to be sorted. The button is found in another sheet.
The numbers to be sorted are found on the range o3 to o289

Hoping to hear from you soonest :)

Regards,
Matthew
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
What is the error message you are getting?

is O3 the header? or the first line of data?

Caleeco
 
Upvote 0
Hi Sir, its says "method 'sort of object'_worksheet failed"

Hi Mr Excel, would like to ask for your inputs on how to make this code work. I'm encountering an error when running it.

Code:
With ActiveWorkbook.Worksheets("Data Analysis").Sort
.SetRange Range("o3:eek:289")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Notes:
The "Data Analysis" is where the numbers are found and is to be sorted. The button is found in another sheet.
The numbers to be sorted are found on the range o3 to o289

Hoping to hear from you soonest :)

Regards,
Matthew
 
Upvote 0
Hi Sir, it says "method 'sort of object"_worksheet failed"
I'm not sure what it meant but i do have an object/ a button that has an assigned macro code to execute this program.
Hoping to hear from you soonest.

Regards,
Matthew
 
Upvote 0
Hello Matthew,

You could trim it all down as follows:-

Code:
Sub SortIt()

Dim ws As Worksheet
Set ws = Sheets("Data Analysis")

With ws.Range("O3:O289")
      .Sort ws.[O3], 1
End With

End Sub

It will work from any sheet. I'm assuming that O3 is where the data starts and is not a heading.

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,085
Members
449,064
Latest member
MattDRT

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