A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VBA Sort Problem



 
 
Thread Tools Display Modes
  #1  
Old November 18th, 2009, 06:19 PM posted to microsoft.public.excel.misc
Tony
external usenet poster
 
Posts: 593
Default VBA Sort Problem

I have five different areas on a worksheet that I want to sort separately.
When it gets to the fourth section ("A43:f" & DMcnt), I get the following
error message:

"RunTime Error 1004
This operation requires the merged cells to be identically sized."

Not sure what I am doing wrong, any suggestions?

I use the following code for each group like this:

With Worksheets("CASB-Toronto Central Phone List").Range("a12:f" & AMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a21:f" & BMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a33:f" & CMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a43:f" & DMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a50:f" & EMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo
End With
  #2  
Old November 18th, 2009, 08:15 PM posted to microsoft.public.excel.misc
Dave Peterson
external usenet poster
 
Posts: 19,791
Default VBA Sort Problem

You have merged cells in that range.

Reformat the cells to remove the merged cells.

In xl2003 menus,
select the range
format|cells|alignment tab|uncheck merge cells



Tony wrote:

I have five different areas on a worksheet that I want to sort separately.
When it gets to the fourth section ("A43:f" & DMcnt), I get the following
error message:

"RunTime Error 1004
This operation requires the merged cells to be identically sized."

Not sure what I am doing wrong, any suggestions?

I use the following code for each group like this:

With Worksheets("CASB-Toronto Central Phone List").Range("a12:f" & AMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a21:f" & BMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a33:f" & CMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a43:f" & DMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a50:f" & EMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo
End With


--

Dave Peterson
  #3  
Old November 18th, 2009, 08:44 PM posted to microsoft.public.excel.misc
Craig
external usenet poster
 
Posts: 506
Default VBA Sort Problem

sounds like there is a merge cell somewhere in the list in the sheet, it is
probably not your VBA but the spreadsheet that has the problem. Try
highlighting all the cells in the fourth area and take all merge options off.

Craig

"Tony" wrote:

I have five different areas on a worksheet that I want to sort separately.
When it gets to the fourth section ("A43:f" & DMcnt), I get the following
error message:

"RunTime Error 1004
This operation requires the merged cells to be identically sized."

Not sure what I am doing wrong, any suggestions?

I use the following code for each group like this:

With Worksheets("CASB-Toronto Central Phone List").Range("a12:f" & AMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a21:f" & BMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a33:f" & CMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a43:f" & DMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
With Worksheets("CASB-Toronto Central Phone List").Range("a50:f" & EMcnt)
.Sort _
Key1:=.Columns(6), _
Order1:=xlAscending, _
Header:=xlNo
End With

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.