runtime error 1004 on sort macro? works on my pc but not on others.

jake.peterson

Board Regular
Joined
May 22, 2012
Messages
68
I recorded this macro to sort a multiple ranges on the same sheet. It runs fine on my machine, but when I email it to someone else they get a runtime error 1004.

Any idea why or how I can fix it?

Sub Sort_Owner()
Range("C7:J26").Select
Selection.Sort Key1:=Range("E7"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SmallScroll Down:=18
Range("C29:J48").Select
ActiveWindow.SmallScroll ToRight:=-2
Application.Width = 1080
Application.Height = 748.5
With ActiveWindow
.Width = 1068.75
.Height = 576.75
End With
Selection.Sort Key1:=Range("E29"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SmallScroll Down:=21
Range("C51:J70").Select
Selection.Sort Key1:=Range("E51"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SmallScroll Down:=18
Range("C73:J92").Select
Selection.Sort Key1:=Range("E73"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SmallScroll Down:=24
Range("C95:J114").Select
Selection.Sort Key1:=Range("E95"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SmallScroll Down:=27
Range("C117:J136").Select
Selection.Sort Key1:=Range("E117"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SmallScroll Down:=21
Range("C139:J158").Select
Selection.Sort Key1:=Range("E139"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SmallScroll Down:=21
Range("C161:J180").Select
Selection.Sort Key1:=Range("E161"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SmallScroll Down:=-18
Selection.Sort Key1:=Range("E161"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWindow.SmallScroll Down:=18
Range("a6").Select
End Sub

Thanks
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
On which line do they get the error and do they have the same version of Excel as you, or an older one?
 
Upvote 0
Same version of excel. fails on Application.Width = 1080
This is just a recorded macro. I can read VBA, but I'm almost useless for debugging.

thanks
 
Upvote 0
You can't set the width if the window is maximised. Why not just maximise rather than setting a specific width?
 
Upvote 0
If I simply eliminate the section that sets the width/height, will that do it? I'm not sure what you mean by "just maximize".
I deleted the width, and height from the copy on my machine and it still worked fine. I assume that would fix the problem. I've asked a few to test it so we'll see.
 
Upvote 0
You should remove all the code for resizing the window and scrolling.
 
Upvote 0

Forum statistics

Threads
1,215,637
Messages
6,125,963
Members
449,276
Latest member
surendra75

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