28. その VBA のコード (1)
Sub AutoFitHeight()
' 対象のセルを決定
Dim targetCell As Range
Set targetCell = ActiveCell
' 「折り返して全体を表示」を設定
targetCell.WrapText = True
29. VBA のコード (2)
' 枠の幅
Dim borderWidth As Variant
borderWidth = 0.63
' 連結したセルの幅を計算
Dim totalWidth As Variant
Dim x As Range
totalWidth = -borderWidth
For Each x In targetCell.MergeArea.Columns
totalWidth = totalWidth + x.ColumnWidth + borderWidth
Next
この値は当て推量かつ固定(汗
30. VBA のコード (3)
' 作業用のWorkBookを作成
Dim work As Worksheet
Set work = ThisWorkbook.Sheets.Add
' 作業用のシートに、対象のセルをコピー
targetCell.Copy
work.Paste
' 貼り付けたセルのセル結合を解く
Selection.UnMerge