0
0

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 1 year has passed since last update.

Excelで選択したセル範囲に斜線を入れる

Last updated at Posted at 2023-08-09

仕事の書類を作成するに当たり、必要となったので作成。
chatGPTでは一発でうまく作成できなかったので、備忘録として。

Sub 選択範囲に斜線を入れる()
    Dim HT, TP, LF, WD, DN As Double
    Dim startCell, endCell As Range
    Dim drawingShape As Shape
   
    With Selection
        ' 選択範囲の開始セルと終了セルを取得
        Set startCell = .Cells(1, 1)
        Set endCell = .Cells(Selection.Rows.Count, Selection.Columns.Count)
       
        WD = .Width
        HT = .Height
        LF = startCell.Left
        DN = startCell.Top + (endCell.Top - startCell.Top + endCell.Height)
   
    End With
   
    Set drawingShape = ActiveSheet.Shapes.AddConnector(msoShapeRectangle, LF, DN, LF + WD, DN - HT)
    drawingShape.line.ForeColor.RGB = RGB(0, 0, 0)

End Sub

こんな感じになります。
image.png

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?