Unmerge cells and fill with duplicate data with VBA code
With the following VBA code, you can quickly unmerge the cells and fill down the values.
1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following macro in the Modulewindow.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| Sub UnMergeSameCell() 'Upadateby20131127 Dim Rng As Range, xCell As Range xTitleId = "KutoolsforExcel" Set WorkRng = Application.Selection Set WorkRng = Application.InputBox( "Range" , xTitleId, WorkRng.Address, Type:=8) Application.ScreenUpdating = False Application.DisplayAlerts = False For Each Rng In WorkRng If Rng.MergeCells Then With Rng.MergeArea .UnMerge .Formula = Rng.Formula End With End If Next Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub |
3. Then press the F5 key to run this code, a dialog is displayed for selecting a range to work with, see screenshot:
4. Click OK, then the merged cells have been unmerged and auto-filled down the original merged values.
https://www.extendoffice.com/documents/excel/1139-excel-unmerge-cells-and-fill.html