Excel 罫線を引く、記録マクロを解読

罫線を引く を解読する
 
なにもないシートに 罫線を引きます。

 
この 罫線を引く動作を マクロの記録 でコードをとります。

 
取得したコード こんなに沢山コードができます。------------------------
Sub Macro6()
 
Range("B2:D4").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("B1").Select
End Sub
 
せっかくなので 解読しました。
-----------------------------------
Sub 罫線を引く()
 
'範囲を選択する
Range("B2:D4").Select
'始めのおまじない(なくてもよい)
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
 
'左枠に縦線を引く
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous'連続
.ColorIndex = 0'色を黒
.TintAndShade = 0'なくてもよい?
.Weight = xlThin' 太さは細く
End With
 
'上枠に引く
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
'下枠に引く
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
 
'右枠を引く
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
 
'内部の縦線を引く
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
 
'内部の横線を引く
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
 
'罫線完成
'一つのセルを選択して範囲選択を解除する
Range("B1").Select
 
End Sub
---------------------------------------------------