vba: Unmerge and fill selection

Babydum

Board Regular
Joined
Feb 24, 2005
Messages
164
Hi,

I'm looking for code that will search for merged cells in the range A1:Z300, and where it finds them it will unmerge them and fill the freed cells with whatever content was in the merged group.

For example, if A1:A3 were merged and contained "Yes", I would want the macro to Unmerge them and put a "Yes" in cells A1, A2 and A3.

I don't know if it will make a difference, but some cells are merged down, some across.

Many thanks in advance for your help.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Code:
Sub UnMergeCells()
Dim Rng     As Range
Dim mCell   As Range
Set Rng = Range("A1:Z300")
Application.ScreenUpdating = False
For Each mCell In Rng.SpecialCells(xlCellTypeBlanks).Areas
    With mCell
        .UnMerge
        .Formula = "=R[-1]C"
        .Value = .Value
    End With
Next mCell
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,210
Members
448,874
Latest member
b1step2far

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top