English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

The error is "run time error 1004" "Application defined or object defined error" It is a SORT macro that sorts a list.. When I click "debug" it highlights this passage in yellow:

Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("B2") _
, Order2:=xlAscending, Key3:=Range("C2"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal

Can I send this to anyone and have them fix it so it works on a mac?

2007-08-13 20:20:15 · 3 answers · asked by n312rc 1 in Computers & Internet Software

3 answers

You need to record the macro in mac,
You know there is a difference between pc and mac don't you??
Why else would they have different names??

2007-08-14 15:02:16 · answer #1 · answered by David M 6 · 0 1

I don't have access to a Mac, but here's my recommendation. Go on a Mac and open your file. Get it to the point where it crashes, and then end the program. Then record a new macro, and do the sort function that you want the macro to do. Stop recording the macro, and open up the code. You can compare the two versions of code and find any potential differences. Depending on how different they are, you may want to do an if statement to have the user input which type of computer they are using.

Ex:

If (MsgBox("Are you using a PC?", vbYesNo) = vbYes) Then
'insert PC code
Else
'insert Mac code
End If


If you don't want to use the user input but you need to include both versions of the code in one file, there is probably some other clever way to determine if its a Mac or PC, perhaps by the direcctory in which the Excel program is located.

Hope this helps!

2007-08-14 10:15:45 · answer #2 · answered by Lowa 5 · 1 0

It sounds like you are having a problem with your selection technique. One thing that may be making a large difference is the data you are selecting. So it may not be that line of code, but instead the line of code that tells Excel what to select. Then when Excel tries to do something with that selection like sort it, it says "WHOAH, Something's wrong!"

See the microsoft website below relating to that type of problem.

http://support.microsoft.com/kb/905164

You also may want to try recording the macro on the Mac to compare the code with what you have now.

What I'd recommend is selecting the range that you know you are going to put your data in don't select entire rows or entire columns, but instead select like Range A1: E80 if you know all of your info, even later on added information will fit inside that. Then name that range. Then use VBA code to select that range and use it as your selection. I think it may be erroring out because it is trying to process entire rows or entire columns. By using a specific group of cells as your selection you avoid that.

2007-08-17 02:05:59 · answer #3 · answered by devilishblueyes 7 · 0 0

fedest.com, questions and answers