Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting data using merged cells as keys

Hi,

I'm not sure if somebody has already posted this here, but my initial
searches failed me. So, after trying to solve this problem for several
days now (since I don't know much about VBA), I would like to ask if
someone from the group can recommend a solution to my problem:

If I have a worksheet, where rows 5 to 7 contains merged cells, ie.
D5:E5, F5:G5, D6:E6, etc., and the other cells below these rows are
all single cells with values. What I would like to do is to sort all
these data, by using one of the rows, ie. row 7 as keys, and then
after sorting this, the original values under these columns will
follow where the new column of the merged cell will be.

Example: (Before)

A B C D E F G
1 Some text here
2 Some text here
3 Some text here
4 Blank row
5 Head1 Head2
6 Head3 Head4
7 A B
8 data1 data2 data3 data4
9 data5 data6 data7 data8
10

When I sort from D5 to G10, using row 7 as my sort keys, what I would
like to happen is this:

A B C D E F G
1 Some text here
2 Some text here
3 Some text here
4 Blank row
5 Head1 Head2
6 Head3 Head4
7 A B
8 data3 data4 data1 data2
9 data7 data8 data5 data6
10

What I had in mind was to create a temporary worksheet, copy the rows
used as sort key to the new worksheet, sort the data on the new
worksheet, then try to determine the old location of data before (ie.
where was A before (F7:G7)), then copy the data from F5:G10 under the
new temporary sheet, and once all data are copied to the temporary
sheet in the new order, copy the whole data back to the original
worksheet. Is there any way easier than this?

Firstly, I needed to know the last column and last row so that I can
copy the appropriate data to the temporary worksheet and be able to
copy these data back to the correct row/column after sorting. With
this alone, I'm already out of ideas on how to implement this on VBA!
Any ideas?

Any advice will be highly appreciated!

Thanks,
Sinobato
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sorting data using merged cells as keys

Sub Tester1()
Dim rng As Range
With Worksheets("Data")
Set rng = .Range("D5").CurrentRegion
End With
MsgBox rng.Address(external:=True)
rng.Copy
With Worksheets("Temp")
.Range("D5").PasteSpecial xlValues
End With


End Sub

--
Regards,
Tom Ogilvy


"Sinobato" wrote in message
m...
Hi,

I'm not sure if somebody has already posted this here, but my initial
searches failed me. So, after trying to solve this problem for several
days now (since I don't know much about VBA), I would like to ask if
someone from the group can recommend a solution to my problem:

If I have a worksheet, where rows 5 to 7 contains merged cells, ie.
D5:E5, F5:G5, D6:E6, etc., and the other cells below these rows are
all single cells with values. What I would like to do is to sort all
these data, by using one of the rows, ie. row 7 as keys, and then
after sorting this, the original values under these columns will
follow where the new column of the merged cell will be.

Example: (Before)

A B C D E F G
1 Some text here
2 Some text here
3 Some text here
4 Blank row
5 Head1 Head2
6 Head3 Head4
7 A B
8 data1 data2 data3 data4
9 data5 data6 data7 data8
10

When I sort from D5 to G10, using row 7 as my sort keys, what I would
like to happen is this:

A B C D E F G
1 Some text here
2 Some text here
3 Some text here
4 Blank row
5 Head1 Head2
6 Head3 Head4
7 A B
8 data3 data4 data1 data2
9 data7 data8 data5 data6
10

What I had in mind was to create a temporary worksheet, copy the rows
used as sort key to the new worksheet, sort the data on the new
worksheet, then try to determine the old location of data before (ie.
where was A before (F7:G7)), then copy the data from F5:G10 under the
new temporary sheet, and once all data are copied to the temporary
sheet in the new order, copy the whole data back to the original
worksheet. Is there any way easier than this?

Firstly, I needed to know the last column and last row so that I can
copy the appropriate data to the temporary worksheet and be able to
copy these data back to the correct row/column after sorting. With
this alone, I'm already out of ideas on how to implement this on VBA!
Any ideas?

Any advice will be highly appreciated!

Thanks,
Sinobato



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting with Merged Cells Debe Excel Discussion (Misc queries) 2 April 24th 07 12:02 PM
Sorting Merged Cells Platinum girl Excel Discussion (Misc queries) 2 March 9th 07 03:21 PM
Sorting merged cells [email protected] Excel Worksheet Functions 3 December 18th 06 11:22 PM
sorting merged cells Jonah Excel Worksheet Functions 3 March 10th 06 12:25 AM
Sorting merged cellsHow do I sort merged cells not identically siz Laval Excel Worksheet Functions 1 November 3rd 04 09:40 PM


All times are GMT +1. The time now is 06:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"