Access VBA to split out ALL merged cell in Excel

别来无恙 提交于 2019-12-06 16:01:23

Try this

Sub UnMergeRanges()
    Dim cl As Range
    Dim rMerged As Range
    Dim v As Variant

    For Each cl In ActiveSheet.UsedRange
        If cl.MergeCells Then
            Set rMerged = cl.MergeArea
            v = rMerged.Cells(1, 1)
            rMerged.MergeCells = False
            rMerged = v
        End If
    Next
End Sub

How it works:

  • Loop through cells in the used range
  • If the cell is part of a merged range
    • Set a Range variable to the Merged Range
    • Record the current value of the Top Left cell in the range into a variable v. This is the value the merged range displays
    • Unmerge the range
    • write the recorded value (v) into all cells of the now unmerged range
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!