SafeFeel.com

Free Computer Networking Security & Software Questions and Answers Website

Macros save failing in excel?

When i step to push the button to set off my macro, it doesnt work and voice i bring error 1004. asks me if i want to End Debug or undo.

here is my macro:

"Sub THE_SORT2()
'
' THE_SORT2 Macro
' Macro record 2007-10-24 by Paul Demchuk
'

'
Selection.SORT Key1:=Range("F3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWorkbook.Save
End Sub"

can you see whats wrong next to it? it worked similar to 10 second ago, in a minute it mystically stopped working.

Cheers


Answers: Normally, the debugger will stress the flash that it is have trouble near surrounded by the code.

From the looks of it, I'd voice this is probably some code that you record next to the Macro Recorder. There are a couple potential problems next to your code.

The Macro Recorder intricate codes exactly what you did. By that I mingy it HAS to sort by band F3. And that could create some problems surrounded by and of itself, especially if F3 isn't at the top of the elected array.

Then you also enjoy the problem of it possibly erroring out if the user doesn't select a reach. You have need of to probably avoid using the Selection portion and use the UsedRange or CurrentRegion propert to identify the nouns. Or you could use a name array.

You any call for to write a better sorting macro, which I could possibly relieve you do if I know more nearly what you are trying to sort. Or you inevitability to brand sure you enjoy the notes other select and that the top row of the elected scope to be row 3 up to that time you ever run the macro. If not, your macro may error out. Row 3 is considered your header row or sorting row depending on whether or not you want row3 to be sort along near the rest of the special notes. According to your macro, Excel is guessing whether your inspection have a header or not (Header: = xlGuess) It really should know whether you enjoy a header or not. By giving a uncompromising yes or no surrounded by the macro that it does or doesn't enjoy a header.

Here's what I did for one I freshly tried out:

ActiveSheet.UsedRange.Sort _
Key1:=Range("Material"), Order1:=xlAscending, _ Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal

Notice that in mine I enjoy a header row. The header row is the row roughly speaking what is to be sorted. I name the cell that I sort by. That means of access if it ever moves it still reference it. Like for instance if i ever insert a column. The used collection may not work for yours though if you are starting your sort on row three and you enjoy background within rows one and two.
Run it and debug it. Then use F8 (I construe or F5) and run through it step by step, find the chain i.e. giving you the problem.