アプリ版:「スタンプのみでお礼する」機能のリリースについて

VBAで、セルに罫線をつけたいのですが、選択範囲の外枠だけに罫線を
ひきたいのに、選択範囲内全ての罫線がひかれてしまいます。
以下のようなものを実行しました。

Public sub Sample()
Range("A1:C3").Select
With Selection
.BorderAround
.Borders.ColorIndex = 1 '線の色を黒にする
.Borders.Weight = xlThin '線を細い線にする
End With
End Sub
どうしたら、選択範囲の外枠だけに線をひけるでしょうか?
よろしくお願いします。

A 回答 (3件)

「新しいマクロの記録」では、


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

と出ました。
    • good
    • 0
この回答へのお礼

有難うございます。
マクロの記録をすれば解決したんですね。

お礼日時:2002/09/12 16:36

以下の形で引けると思います。



Sub test()
Worksheets("Sheet1").Range("A1:c3").BorderAround _
ColorIndex:=1, Weight:=xlThin
End Sub
    • good
    • 0
この回答へのお礼

外枠以外(BordersStyle)の罫線の時は
Borders.ColorIndex = 1 やBorders.Weight = xlThin
にして、BoderAroundの罫線の時は
BorderAround ColorIndex:= 1 やBirderAround Weight:= xlThin
のようにスペースとコロンをいれればいいのですね?

お礼日時:2002/09/12 16:33

##1で出ましたが


Sub test01()
Range("a2:d5").Borders(xlEdgeTop).LineStyle = xlThin
Range("a2:d5").Borders(xlEdgeBottom).LineStyle = xlThin
Range("a2:d5").Borders(xlEdgeRight).LineStyle = xlThin
Range("a2:d5").Borders(xlEdgeLeft).LineStyle = xlThin
End Sub
で最低限線が引けます。xlEdge○○が範囲周辺線を示す。
1
    • good
    • 0
この回答へのお礼

有難うございます。
選択範囲の外枠を一つずつ罫線をひいていけばよかったのですね。

お礼日時:2002/09/12 16:35

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