プロが教えるわが家の防犯対策術!

右側に空白の行を一つつくって枠を作りたいです。
たとえば、G100が一番右下とするとH100まで枠を作りたいのですが、きれいにかくにはどうしたらよいでしょうか?
マクロ記録でやると、下のようになるのですが右下が100で有るとは限らないのでその行を定義する必要があると思うのですが、そのあたりがさっぱりわかりません。
よろしくお願いいたします。

Sub Macro1()

Selection.End(xlDown).Select
Range("H100").Select
Range(Selection, Selection.End(xlUp)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlToLeft)).Select
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 回答 (3件)

G列の最終行で判断するのであれば、以下の1行で出来ます。



Sub macro()
Range("A1:H" & Range("G" & Rows.Count).End(xlUp).Row).Borders.Weight = xlThin
End Sub
    • good
    • 0
この回答へのお礼

ご回答ありがとうございました。
思っていた以上にすばらしい考え方でした。

お礼日時:2011/02/05 14:48

A1から右下のセルまでデータが入っていると想定して、



Sub Macro2()

Range("A1").CurrentRegion.Select
Selection.Resize(, Selection.Columns.Count + 1).Select
Selection.Borders.LineStyle = xlContinuous

End Sub
    • good
    • 0

A1からG100にデータが入っていると想定して、



Sub Macro2()

Range("A1").CurrentRegion.Select
Selection.Resize(, Selection.Columns.Count + 1).Select
Selection.Borders.LineStyle = xlContinuous

End Sub
    • good
    • 0

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