VBATips

セルの罫線のみコピペする処理をパーツ化する【Borders.LineStyle】【ExcelVBA】

セルの罫線のみコピペしたい場合があります。
セルをそのままであればCopyとPasteでもいいのですが、
罫線のみの場合はコードをパーツ化して、使用したほうが簡単です。

セルの罫線のみコピペする処理のサンプルコード

'■セルの罫線をコピーアンドペーストする
Public Function Call_BordersLineStyleWeightCopyPaste(CopyRange As Range, PasteRange As Range)
    PasteRange.Borders(xlEdgeTop).LineStyle = CopyRange.Borders(xlEdgeTop).LineStyle
    PasteRange.Borders(xlEdgeTop).Weight = CopyRange.Borders(xlEdgeTop).Weight
    PasteRange.Borders(xlEdgeBottom).LineStyle = CopyRange.Borders(xlEdgeBottom).LineStyle
    PasteRange.Borders(xlEdgeBottom).Weight = CopyRange.Borders(xlEdgeBottom).Weight
    PasteRange.Borders(xlEdgeLeft).LineStyle = CopyRange.Borders(xlEdgeLeft).LineStyle
    PasteRange.Borders(xlEdgeLeft).Weight = CopyRange.Borders(xlEdgeLeft).Weight
    PasteRange.Borders(xlInsideHorizontal).LineStyle = CopyRange.Borders(xlInsideHorizontal).LineStyle
    PasteRange.Borders(xlInsideHorizontal).Weight = CopyRange.Borders(xlInsideHorizontal).Weight
    PasteRange.Borders(xlInsideVertical).LineStyle = CopyRange.Borders(xlInsideVertical).LineStyle
    PasteRange.Borders(xlInsideVertical).Weight = CopyRange.Borders(xlInsideVertical).Weight
    PasteRange.Borders(xlEdgeRight).LineStyle = CopyRange.Borders(xlEdgeRight).LineStyle
    PasteRange.Borders(xlEdgeRight).Weight = CopyRange.Borders(xlEdgeRight).Weight
End Function

実際の使い方

Public Sub Sample
     Call Call_BordersLineStyleWeightCopyPaste(Range("A1:A10"),Range("C1:C10"))
End Sub

注意点

  • 特にありません。

関連記事

コメント

タイトルとURLをコピーしました