RUN-TIME ERROR IN SIMPLE SORT MACRO

L

Lindsay Graham

I have a simple macro that is supposed to call a named range 'Catalogue' and
sort it in a specified order. But I always get "Run-time error '1004':
This operation requires the merged cells to be identically sized."

The macro is:

Sub SortNFAuthor()
'
' SortNFAuthor Macro
' Macro recorded 13/9/2004 by Lindsay D. Graham
'
' Keyboard Shortcut: Ctrl+Shift+S
'
Application.Goto Reference:="Catalogue"
Selection.Sort Key1:=Range("K3"), Order1:=xlAscending,
Key2:=Range("A3") _
, Order2:=xlAscending, Header:=xlYes, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom
End Sub

The Header in the table to be sorted is 2 rows, and in some columns (but not
all) the 2 header cells are merged. If this is what's causing the problem,
why is it not a problem when I do the sort manually (ie, without using the
macro)? Can anyone help?

Lindsay Graham
Canberra, Australia
 
I

icestationzbra

merged cells do pose problems while sorting, that might be the proble
you are running into. suggest that you unmerge the cells and tr
running the macro. if it still does not work, someone might be able t
help you with another solution
 
I

icestationzbra

merged cells do pose problems while sorting, that might be the proble
you are running into. suggest that you unmerge all the cells in th
region to be sorted and then try running the macro. if it still doe
not work, someone might be able to help you with another solution
 
L

Lindsay Graham

But how come there is no problem sorting when not using a macro? I often
sort tables where the heading contains merged cells, and have never had a
problem. Why is there a problem when using a macro, when the macro
supposedly duplicates what works OK manually?

And I hasten to add that there are no merged cells within the area of the
table to be sorted, just within the header rows which are not sorted.

Lindsay Graham
 
B

Bob Phillips

Remove the merged cells, they are more problem than they are worth. Replace
the function with Format>Cells>Alignment, and in the Horizontal selection,
choose Center Across Selection
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top