表全体に罫線を入れたいのですが、空白セルがあるので「えんぴつ」
の部分だけの罫線になってしまいます。
どのようにすれば、表全体に対しての罫線になりますか?
【補足】
・毎回行の数は異なりますが、区切りとしての空白セル(行)は必ずあります。
Sub 罫線作成()
Dim table_range As Range
Range("A1").Select
Set table_range = ActiveCell.CurrentRegion
With table_range
.Borders(xlTop).Weight = xlThin
.Borders(xlBottom).Weight = xlThin
.Borders(xlLeft).Weight = xlThin
.Borders(xlRight).Weight = xlThin
.BorderAround Weight:=xlThin
End With
End Sub
同時に
①A列からD列(任意)が連続した空白セルの場合、「塗りつぶし(任意)」
「フォントは白」に設定したい。
※条件付きで「空白セルに色をつける」と、あとでそのセルに文字を入れる関係で
塗りつぶしの色が消えてしまうので、条件付き以外
②A列に「総計」がある行を全て「塗りつぶし(任意)」
教えていただくと大変助かります。宜しくお願いします。
シートにその表しかなければCurrentRegionのかわりにUsedRangeを使うことで表全体を取得できます。
Sub Macro() Dim table_range As Range Dim lastRow As Long Dim i As Long Set table_range = ActiveSheet.UsedRange With table_range .Borders(xlTop).Weight = xlThin .Borders(xlBottom).Weight = xlThin .Borders(xlLeft).Weight = xlThin .Borders(xlRight).Weight = xlThin .BorderAround Weight:=xlThin End With lastRow = ActiveSheet.UsedRange.Rows.Count For i = 1 To lastRow If Cells(i, 1).Value = "" And Cells(i, 2).Value = "" And _ Cells(i, 3).Value = "" And Cells(i, 4).Value = "" Then Range(Cells(i, 1), Cells(i, 4)).Interior.ColorIndex = 8 Range(Cells(i, 1), Cells(i, 4)).Font.Color = 2 End If If Cells(i, 1).Value = "総計" Then Range(Cells(i, 1), Cells(i, 4)).Interior.ColorIndex = 14 End If Next i End Sub
解決しました!素晴らしいです!
本当にありがとうございました。