ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Border VBA (https://www.excelbanter.com/excel-programming/296482-border-vba.html)

pete

Border VBA
 
When I recorded this part of my macro I noticed that all
the option for the Left,Right,Top and Bottom edges of the
cells are the same. Is there a way to combine all these
into one selection to eliminate the repeatitive code.

Range("DCard1:Dcard1a").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle =
xlNone

Thanks
Pete

Rob Bovey

Border VBA
 
Hi Pete,

Try this:

Range("DCard1:Dcard1a").BorderAround

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Pete" wrote in message
...
When I recorded this part of my macro I noticed that all
the option for the Left,Right,Top and Bottom edges of the
cells are the same. Is there a way to combine all these
into one selection to eliminate the repeatitive code.

Range("DCard1:Dcard1a").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle =
xlNone

Thanks
Pete




SOS[_10_]

Border VBA
 
Hi Pete,

I remember having the same problem and this sorted it.

Sub Test

Range("DCard1:Dcard1a").Borders.Linestyle = xlContinuous

End Sub

This means that you don't even have to select the range prior t
applying borders.

Regards

Seamu

--
Message posted from http://www.ExcelForum.com


SOS[_11_]

Border VBA
 
Rob,

I found that when I tried your code of:

Range("DCard1:DCard1a").BorderAround

it didn't do anything to the range and even after adding

(xlContinuous)

to the end of the line it only put a border around the whole selectio
rather than round each cell in the selection.

Am I missing something?

Regards

Seamu

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Border VBA
 
add a weight

Range("DCard1:DCard1a")..Borderaround Weight:=xlThin

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"SOS " wrote in message
...
Rob,

I found that when I tried your code of:

Range("DCard1:DCard1a").BorderAround

it didn't do anything to the range and even after adding

(xlContinuous)

to the end of the line it only put a border around the whole selection
rather than round each cell in the selection.

Am I missing something?

Regards

Seamus


---
Message posted from http://www.ExcelForum.com/




Rob Bovey

Border VBA
 
Hi Seamus,

I found that when I tried your code of:
Range("DCard1:DCard1a").BorderAround
it didn't do anything to the range and even after adding
(xlContinuous)


Yep, I screwed up. The LineStyle argument is required.

it only put a border around the whole selection
rather than round each cell in the selection.
Am I missing something?


The code in the original post was only surounding the entire range with
a border. If you want every cell within the range to have a border you have
to add two more lines:

With Range("DCard1:DCard1a")
.BorderAround xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End With

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"SOS " wrote in message
...
Rob,

I found that when I tried your code of:

Range("DCard1:DCard1a").BorderAround

it didn't do anything to the range and even after adding

(xlContinuous)

to the end of the line it only put a border around the whole selection
rather than round each cell in the selection.

Am I missing something?

Regards

Seamus


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 03:19 AM.

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