PDA

Click to See Complete Forum and Search --> : Merged cells problem


wossname
Oct 6th, 2003, 06:07 AM
I've got a spreadsheet with loads of merged cells in it.

All merges are 1 column wide but any number of rows long.

I want to unmerge each one and fill each of its constituents with its text. In other words

instead of...

Hello

I want...

Hello
Hello
Hello
Hello
Hello
Hello

Any ideas about what the code would be. I haven't much VBA knowledge, since VB proper is my normal weapon of choice. Not used to excel programming.

Cheers.

WorkHorse
Oct 6th, 2003, 06:54 PM
I think this should work.

Sub UnmergeAllWithFill()
For Each c In ActiveSheet.Range("A1:" & ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Address)
If c.MergeCells Then
Set rngMerged = c.MergeArea
rngMerged.UnMerge
rngMerged.Value = rngMerged.Cells(1, 1).Value
End If
Next c
End Sub

wossname
Oct 7th, 2003, 04:44 AM
Excellent (please excuse the awful pun)

Nice one, that works fine.

Cheers.