Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unmerge cells and fill duplicate data

2,563 views
Skip to first unread message

Dawn

unread,
Aug 5, 2009, 3:47:02 PM8/5/09
to
I have a report that contains merged cells. I need to get rid of the merged
cells and then have the data from the first row repeated in the blank rows.
I found a macro to umerge all the cells (Cells.MergeCells = False) so far so
good! But now I need to repeat the data. I have two columns in the sheet
that will need to be unmerged and have the data repeated.

The existing workbook looks like this, with the cells for W, X, Y, and Z
merged so they span one or more rows, it varies:

X Y 1 2 3
4 5 6
Z W 7 8 9
1 2 3

I need it like this, so I can successfully filter:

X Y 1 2 3
X Y 4 5 6
Z W 7 8 9
Z W 1 2 3

TIA for any help!

Barb Reinhardt

unread,
Aug 5, 2009, 4:08:01 PM8/5/09
to
Try something like this


Option Explicit

Sub Test()

Dim r As Excel.Range
Dim r1 As Excel.Range
Dim myR As Excel.Range

For Each r In ActiveSheet.UsedRange
Debug.Print r.Address, r.Count
If r.MergeArea.Count > 1 Then
Set myR = r.MergeArea
r.UnMerge
For Each r1 In myR
r1.Value2 = myR.Value2
Next r1
End If
Next r

End Sub

HTH,
Barb Reinhardt

ryguy7272

unread,
Aug 5, 2009, 4:28:08 PM8/5/09
to
Is the 4, 5, & 6 under the 1, 2, & 3? If so, and if you want to fill the
blanks below x & Y, look at this:
http://www.contextures.com/xlDataEntry02.html

If that doesn't work, please post back with a little more info.

Thanks,
Ryan--

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.

GES

unread,
Nov 29, 2009, 1:26:01 AM11/29/09
to
This is AWESOME! Thank you so much for saving me hours of time! I've always
wondered how to do this.
GES

bigbre...@googlemail.com

unread,
Jan 13, 2013, 4:28:20 PM1/13/13
to
Add another column (B) and then add this function to fill in everything until another entry for the merged cell in col A:
=IF(A2=0,B1,A2).

This assumes you have one header.

cibi...@gmail.com

unread,
May 10, 2013, 8:54:33 AM5/10/13
to
For two or more rows, this will not work.
0 new messages