Skip to content

Instantly share code, notes, and snippets.

@haruo31
Last active December 11, 2018 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haruo31/c753015e2da84f7745dbe1a64dbf0fd5 to your computer and use it in GitHub Desktop.
Save haruo31/c753015e2da84f7745dbe1a64dbf0fd5 to your computer and use it in GitHub Desktop.
The Excel VBA script un-merge cells and copy contents to them. It runs on current worksheet. - Excelの開いているシートにある全ての結合セルを分解し、それぞれに内容をコピーするVBA
Option Explicit
Sub breakUpMergedCells()
Dim curSheet As Worksheet
Dim eCell As Range, curRange As Range
Dim curAddr As String
Dim fillCell As Range
Dim filledValue As String
Set curSheet = ActiveSheet
Set eCell = curSheet.Cells.SpecialCells(xlCellTypeLastCell)
For Each curRange In curSheet.Range(curSheet.Range("A1"), eCell)
If curRange.MergeCells Then
curAddr = curRange.MergeArea.Address
filledValue = curRange.Formula
curRange.UnMerge
For Each fillCell In curSheet.Range(curAddr)
fillCell.Formula = filledValue
Next
End If
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment