Macro Sort

MyCuteHeart

New Member
Joined
Mar 7, 2012
Messages
6
Hi Guyz,

Been recording a macro that sorts different columns at a time but after recording it and tried the macro, it always give me an error and does not do the sorthing. See below part of the code where it gives an error. Please help. Thanks a lot.

Text in bold is the one making the error.

Range("D2:D31").Select
ActiveWorkbook.Worksheets("jag2_ptr_thermal prt rev10 03_0").Sort.SortFields. _
Clear

ActiveWorkbook.Worksheets("jag2_ptr_thermal prt rev10 03_0").Sort.SortFields. _
Add Key:=Range("D2:D31"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi Jproffer,

The macro was recorded that way. I tried erasing this line, then the next line was the next error. :(
 
Upvote 0
Hi Smith,

The worksheet is not protected. And I get an error like this.

Run-time error '1004':
Application-defined or object-defined error

then when I clik debug, it points to the code in bold letters above.
Please help. Thanks
 
Upvote 0
I ran it on a sheet with that name and it ran through....it didn't DO anything, but it didn't error. Are you sure the sheet name is correct?...Object error sounds like it's something like that.
 
Upvote 0
I ran it on a sheet with that name and it ran through....it didn't DO anything, but it didn't error. Are you sure the sheet name is correct?...Object error sounds like it's something like that.
Hi jproffer,

How to know if the sheet has a name as that. Sorry I'm new in macro.
What I do is, I record the macro in an excel file and then I export the macro and I import the said macro to another excel file and try to run it. Then it gives me an error. What should I do? Thanks.
 
Upvote 0
The name on the tab should match the code exactly or it won't run.

Do you mean you record it in one workbook, then move it to a second workbook?
 
Upvote 0
The name on the tab should match the code exactly or it won't run.

Do you mean you record it in one workbook, then move it to a second workbook?
Hi Jproffer,

Yah. I got it now. Thank you very much Sir. Hope to help me again if I need a help. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,411
Members
448,894
Latest member
spenstar

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