Problems with sort

B

bigjim

I'm using excel 2003. I want to sort data formatted as text in a column.
Most of the cells in the column are blank. I am using the following code:

With Sheets("MarginAnalysis")
..Cells.Sort Key1:=.Range("b225:B270"), _
Order1:=xlAscending, Header:=xlNo, _
MatchCase:=False, Orientation:=xlTopToBottom
End With

The error I get is "This operation requires the merged cells to be
identically sized. " There are no merged cells anywhere in the range
selected. When I go to the worksheet "marginanalysis" after the program
stops the range b225:b282 is highlighted.??
I'm lost and any help would be appreciated.

Jim
 
J

Jacob Skaria

Right click the range and FormatCells-->Alignment. Under 'Text Control' check
the status of 'MergeCells'
 
J

Jim Cone

You are telling Excel to sort the entire sheet in this portion of the code...
Sheets("MarginAnalysis").Cells

The "Key1:=.Range("b225:B270")" portion specifies the column to sort by.

Change .Cells to .Selection if you want to sort the selection.
However, the selection must intersect with column B.
--
Jim Cone
Portland, Oregon USA



"bigjim"
<[email protected]>
wrote in message
I'm using excel 2003. I want to sort data formatted as text in a column.
Most of the cells in the column are blank. I am using the following code:

With Sheets("MarginAnalysis")
..Cells.Sort Key1:=.Range("b225:B270"), _
Order1:=xlAscending, Header:=xlNo, _
MatchCase:=False, Orientation:=xlTopToBottom
End With

The error I get is "This operation requires the merged cells to be
identically sized. " There are no merged cells anywhere in the range
selected. When I go to the worksheet "marginanalysis" after the program
stops the range b225:b282 is highlighted.??
I'm lost and any help would be appreciated.

Jim
 
B

bigjim

OK, I tried this code:

With ActiveWorkbook.Sheets("MarginAnalysis").Range("b225:b270").Select
Selection.Sort Key1:=Range("b225"), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End With

Now I'm getting this error:
"Sort reference is not valid. Make sure it's witing the data ou want to
sort and the first sort by box isn't the same or blank.

I'm not sure what that is saying.

Jim
 
J

Jacob Skaria

Ctrl+A and check whether there are any merge cells...and try the below code.

ActiveWorkbook.Sheets("MarginAnalysis").Range("b25:b70"). _
Sort Key1:=Range("b25"), Order1:=xlDescending


If this post helps click Yes
 
J

john

this worked for me.

With ActiveWorkbook.Sheets("MarginAnalysis")
.Range("b225:b270").Sort Key1:=.Range("b225"), _
Order1:=xlDescending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End With
 

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