PC Review


Reply
Thread Tools Rate Thread

How do I sort a table w/ merged cells

 
 
John
Guest
Posts: n/a
 
      21st Feb 2009
I have a 12 column table (cols B -M). Each row is formated the same and the
last 8 columns of each row (cols F thru M, all having a width of 9) are
merged into single cells in the row.

What code could I use to place the rows in alphabetic order, first by col C
and then by col B?

Whenever I try to sort this table manually using the Sort option on the Data
Ribbon, I get the error: This operation requires the merged cells to be
identically sized.

I appreciate your help, -John
 
Reply With Quote
 
 
 
 
Tom Hutchins
Guest
Posts: n/a
 
      21st Feb 2009
Unmerge the cells in columns F-M, and set the column width of F to 72. Then
sort normally. All the data is in column F anyway; columns G-M are empty.

Hope this helps,

Hutch

"John" wrote:

> I have a 12 column table (cols B -M). Each row is formated the same and the
> last 8 columns of each row (cols F thru M, all having a width of 9) are
> merged into single cells in the row.
>
> What code could I use to place the rows in alphabetic order, first by col C
> and then by col B?
>
> Whenever I try to sort this table manually using the Sort option on the Data
> Ribbon, I get the error: This operation requires the merged cells to be
> identically sized.
>
> I appreciate your help, -John

 
Reply With Quote
 
John
Guest
Posts: n/a
 
      21st Feb 2009
Tom, Good idea except my boss won't be too happy when I push all his summary
stats way to the right on the worksheet w/ the table! The rows above the
table contain a bunch of columns of summary data and the table spans these
rows. I had to merge all these cells in table rows in order to compensate
and do the table like my boss wants. There is a similar problem w/ data
below the table. I can't move the table to the right either since it has to
print in line w/ all the other data.

Sooo. How do I sort a table containing merged cells?

"Tom Hutchins" wrote:

> Unmerge the cells in columns F-M, and set the column width of F to 72. Then
> sort normally. All the data is in column F anyway; columns G-M are empty.
>
> Hope this helps,
>
> Hutch
>
> "John" wrote:
>
> > I have a 12 column table (cols B -M). Each row is formated the same and the
> > last 8 columns of each row (cols F thru M, all having a width of 9) are
> > merged into single cells in the row.
> >
> > What code could I use to place the rows in alphabetic order, first by col C
> > and then by col B?
> >
> > Whenever I try to sort this table manually using the Sort option on the Data
> > Ribbon, I get the error: This operation requires the merged cells to be
> > identically sized.
> >
> > I appreciate your help, -John

 
Reply With Quote
 
Tom Hutchins
Guest
Posts: n/a
 
      21st Feb 2009
Sorry if this posts twice. One way is to unmerge the cells, sort the table,
then re-merge the cells. Here is an example:

Sub SortTable()
Dim Tbl As Range
'Start with a cell in the table selected
'Select all the cells in the current region
Selection.CurrentRegion.Select
Set Tbl = Selection
'Unmerge all merged cells.
Selection.UnMerge
'Now sort the table
Tbl.Sort Key1:=Range("A5"), Key2:=Range("B5"), Header:=xlYes
'Walk down through each row of the table & re-merge cols F-M
Tbl.Cells(1, 1).Activate
Do While Not Intersect(ActiveCell, Tbl) Is Nothing
Range("F" & ActiveCell.Row & ":M" & ActiveCell.Row).Merge
ActiveCell.Offset(1, 0).Activate
Loop
'Free the object variable
Set Tbl = Nothing
End Sub

You would have to edit the Sort command parameters, of course. You also may
need to use something other than CurrentRegion to specify the table range.

Hutch

"John" wrote:

> Tom, Good idea except my boss won't be too happy when I push all his summary
> stats way to the right on the worksheet w/ the table! The rows above the
> table contain a bunch of columns of summary data and the table spans these
> rows. I had to merge all these cells in table rows in order to compensate
> and do the table like my boss wants. There is a similar problem w/ data
> below the table. I can't move the table to the right either since it has to
> print in line w/ all the other data.
>
> Sooo. How do I sort a table containing merged cells?
>
> "Tom Hutchins" wrote:
>
> > Unmerge the cells in columns F-M, and set the column width of F to 72. Then
> > sort normally. All the data is in column F anyway; columns G-M are empty.
> >
> > Hope this helps,
> >
> > Hutch
> >
> > "John" wrote:
> >
> > > I have a 12 column table (cols B -M). Each row is formated the same and the
> > > last 8 columns of each row (cols F thru M, all having a width of 9) are
> > > merged into single cells in the row.
> > >
> > > What code could I use to place the rows in alphabetic order, first by col C
> > > and then by col B?
> > >
> > > Whenever I try to sort this table manually using the Sort option on the Data
> > > Ribbon, I get the error: This operation requires the merged cells to be
> > > identically sized.
> > >
> > > I appreciate your help, -John

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot sort merged cells Blue Max Microsoft Excel Discussion 0 20th Feb 2009 01:50 AM
How can I sort an Excel Doc containing merged & non-merged cells? KellyH Microsoft Excel Misc 11 10th Jun 2008 04:12 AM
How to sort merged cells =?Utf-8?B?U29ydCBtZXJnZWQgY2VsbHM=?= Microsoft Excel Worksheet Functions 3 11th Mar 2005 04:07 PM
How to sort merged cells =?Utf-8?B?aW1hb3Jhbmdl?= Microsoft Excel Worksheet Functions 0 11th Mar 2005 03:41 PM
Sorting merged cellsHow do I sort merged cells not identically siz =?Utf-8?B?TGF2YWw=?= Microsoft Excel Worksheet Functions 1 3rd Nov 2004 09:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:47 PM.