◆罫線を引
色々な表の操作をマクロで記述して行くと、最後は罫線を引いて見栄えを良くしたく
なります。
罫線を引くマクロのサンプルです。
コメントを読んでもらえば特に説明は必要ないと思います。
example10 をダウンロードして、動作を確認してください。
.Weight = xlThick (太線)
.ColorIndex = 3 (赤)
を変更して太さや色をカスタマイズしてお使いください。
Sub Solidline_UpSide(xRow, xCol1, xCol2)
With Range(Cells(xRow, xCol1), _
Cells(xRow, xCol2)).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
Sub Solidline_LeftSide(xRow1, xRow2, xCol)
With Range(Cells(xRow1, xCol), _
Cells(xRow2, xCol)).Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
Sub Solidline_RightSide(xRow1, xRow2, xCol)
With Range(Cells(xRow1, xCol), _
Cells(xRow2, xCol)).Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
Sub Solidline_BottomSide(xRow, xCol1, xCol2)
With Range(Cells(xRow, xCol1), _
Cells(xRow, xCol2)).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
Sub Dotedline_UpSide(xRow, xCol1, xCol2)
With Range(Cells(xRow, xCol1), _
Cells(xRow, xCol2)).Borders(xlEdgeTop)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
Sub Dotedline_LeftSide(xRow1, xRow2, xCol)
With Range(Cells(xRow1, xCol), _
Cells(xRow2, xCol)).Borders(xlEdgeLeft)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
Sub Dotedline_RightSide(xRow1, xRow2, xCol)
With Range(Cells(xRow1, xCol), _
Cells(xRow2, xCol)).Borders(xlEdgeRight)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
Sub Dotedline_BottomSide(xRow, xCol1, xCol2)
With Range(Cells(xRow, xCol1), _
Cells(xRow, xCol2)).Borders(xlEdgeBottom)
.LineStyle = xlDash
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub