1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

脱Excelへの一歩 全ての結合セルを解除する

Posted at

はじめに

Excelで作られたIPアドレス管理表をDBに投げ込むのに、下記の上の表ように結合されてたりするといろいろと面倒なもの
image.png
ということで、下表のようなワークブック内の各シートの結合セルを解除し、解除された各セルに同じ値を入れるマクロを作成しました

マクロの内容

Option Explicit

Sub releaseMerge()
    Dim ws As Worksheet
    Dim r As Range
    For Each ws In Worksheets
        For Each r In ws.UsedRange    
            If r.MergeCells = True Then
                Dim v As String, rc As String            
                ' 結合セルの値を取得
                v = r.Text
                ' セル範囲を取得
                rc = r.MergeArea.Address(False, False)
                ' 結合セルを解除
                r.MergeArea.UnMerge
                ' 解除した各セルに値を入れる
                ws.Range(rc).Value = v
            End If    
        Next
    Next
End Sub

これでDBへのインポートが捗るはず

終わりに

今年は我が社にも自動化、RPAの波が。。。
まだまだExcelが全盛の会社も多いはず。効率化の一助になれば幸いです

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?