Why doesn't this create a boxed range?

  • Thread starter gimme_this_gimme_that
  • Start date
G

gimme_this_gimme_that

Adapted from the recorder. What must be changed to create a border box
around boxrng?

Thanks.

Sub t()
Dim startcell As Range, endcell As Range, boxrng As Range
Dim b As Workbook
Dim s As Worksheet
Set b = ActiveWorkbook
Set s = b.Sheets("Sheet1")


Set startcell = s.Cells(2, 2)
Set endcell = s.Cells(5, 5)
Set boxrng = Range(startcell, endcell)
boxrng.Borders(xlDiagonalDown).LineStyle = xlNone
boxrng.Borders(xlDiagonalUp).LineStyle = xlNone
boxrng.Borders(xlEdgeLeft).LineStyle = xlContinous
boxrng.Borders(xlEdgeTop).LineStyle = xlContinuous
boxrng.Borders(xlEdgeBottom).LineStyle = xlContinous
boxrng.Borders(xlEdgeRight).LineStyle = xlContinuous
boxrng.Borders(xlInsideVertical).LineStyle = xlNone
boxrng.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub
 
N

NickHK

Try this way :

With ActiveWorkbook.Worksheets("Sheet1")
With .Range(.Cells(2, 2), .Cells(5, 5))
.Borders.LineStyle = xlNone
.BorderAround LineStyle:=xlContinuous, Weight:=xlThick
End With
End With

NickHK
 
B

Bob Phillips

Couple of typos

Sub t()
Dim startcell As Range, endcell As Range, boxrng As Range
Dim b As Workbook
Dim s As Worksheet
Set b = ActiveWorkbook
Set s = b.Sheets("Sheet1")


Set startcell = s.Cells(2, 2)
Set endcell = s.Cells(5, 5)
Set boxrng = Range(startcell, endcell)
boxrng.borderaround(
End Sub


can be simplified

Sub t()
Dim startcell As Range, endcell As Range, boxrng As Range
Dim b As Workbook
Dim s As Worksheet
Set b = ActiveWorkbook
Set s = b.Sheets("Sheet1")


Set startcell = s.Cells(2, 2)
Set endcell = s.Cells(5, 5)
Set boxrng = Range(startcell, endcell)
boxrng.BorderAround LineStyle:=xlContinuous, Weight:=xlThin
End Sub

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top