ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Why doesn't this create a boxed range? (https://www.excelbanter.com/excel-programming/377474-why-doesnt-create-boxed-range.html)

[email protected]

Why doesn't this create a boxed range?
 
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


NickHK

Why doesn't this create a boxed range?
 
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

wrote in message
ups.com...
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




Bob Phillips

Why doesn't this create a boxed range?
 
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)

wrote in message
ups.com...
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





All times are GMT +1. The time now is 11:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com