Sub リストの罫線()
Dim ws As Worksheet
Dim LastRow As Long
Dim LastCol As Long
Dim i As Long
Dim RangeToFormat As Range
' シートを指定(例: シート1)
Set ws = ThisWorkbook.Sheets("Sheet1")
' 最終行(データがある最後の行)を取得
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' 最終列(データがある最後の列)を取得
LastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
' 縦線はすべて実線
For i = 1 To LastRow
Set RangeToFormat = ws.Range(ws.Cells(i, 1), ws.Cells(i, LastCol))
' 左縦線と右縦線を実線に設定
With RangeToFormat.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
End With
With RangeToFormat.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
End With
Next i
' 横線を設定
For i = 1 To LastRow
Set RangeToFormat = ws.Range(ws.Cells(i, 1), ws.Cells(i, LastCol))
If i = 1 Then
' タイトル行の下(2行目の上)は実線
With RangeToFormat.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
End With
ElseIf i = LastRow Then
' 最終行の下(最終行の1つ上)は実線
With RangeToFormat.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
End With
Else
' その他の行の下は点線
With RangeToFormat.Borders(xlEdgeBottom)
.LineStyle = xlDot
.ColorIndex = 0
.Weight = xlThin
End With
End If
Next i
End Sub