dポイントプレゼントキャンペーン実施中!

マクロ記録をつかって、選択している範囲に黒の格子を付けるマクロをボタンを作成しました。
(質問の下に、記録した内容を添付します)

実際に、格子を作るのには不要な行がたくさんあると思うのですが、不要な箇所をどう見つければいいのか教えてください。

個人的には、with以下の構文は標準設定しているだけなので不要かと思うのですが、何度も設定されていてくどく感じられます。
記録した後に、一括してこれらの記録を消す方法があればあわせて教えてください。


---
Sub 格子マクロ()

Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub

A 回答 (2件)

こんばんは!



単に選択セルにが格子罫線になればよい訳ですよね?
線の太さや色は指定なしだと、ごく簡単に

Sub 格子()
Selection.Borders.LineStyle = xlContinuous
End Sub

だけでOKだと思います。m(_ _)m
    • good
    • 0

通常は


sub macro1()
selection.borders.linestyle = xlcontinuous
end sub
で十分です。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!