ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   cell formatting - apply borders (https://www.excelbanter.com/excel-programming/330926-cell-formatting-apply-borders.html)

David

cell formatting - apply borders
 
Greetings and TIA for your time
I would like to apply a hairline border to every cell in a range. I can
mimic the recorder code with a long list of instructions (xlLeft, xlRight,
etc.) but is their a short and tidy method?
--
David

Peter T

cell formatting - apply borders
 
Hi David

I would like to apply a hairline border to every cell in a range. I can
mimic the recorder code with a long list of instructions (xlLeft, xlRight,
etc.) but is their a short and tidy method?


Sub test()
Dim bdrs As Borders

Set bdrs = Range("b3:e6").Borders
bdrs.LineStyle = xlContinuous
bdrs.Weight = xlHairline
bdrs.ColorIndex = 5

End Sub

Regards,
Peter T



David

cell formatting - apply borders
 
Thanks Peter,
Works good,
Since posting I also found:
Selection.BorderAround xlContinuous, xlHairline
works good too
--
David


"Peter T" wrote:

Hi David

Sub test()
Dim bdrs As Borders

Set bdrs = Range("b3:e6").Borders
bdrs.LineStyle = xlContinuous
bdrs.Weight = xlHairline
bdrs.ColorIndex = 5

End Sub

Regards,
Peter T




Peter T

cell formatting - apply borders
 
Hi David,

Since posting I also found:
Selection.BorderAround xlContinuous, xlHairline
works good too


That applies borders to the outside edges of the range but not the insides.
You originally asked

I would like to apply a hairline border to every cell in a range.


Only if your range comprises of one or more single cell areas would both
methods do same. So if you only want to do the outside, use "BorderAround",
otherwise the apply to the entire Borders collection in one go (assuming you
want same properties for all).

Regards,
Peter T


"David" wrote in message
...
Thanks Peter,
Works good,
Since posting I also found:
Selection.BorderAround xlContinuous, xlHairline
works good too
--
David


"Peter T" wrote:

Hi David

Sub test()
Dim bdrs As Borders

Set bdrs = Range("b3:e6").Borders
bdrs.LineStyle = xlContinuous
bdrs.Weight = xlHairline
bdrs.ColorIndex = 5

End Sub

Regards,
Peter T






David

cell formatting - apply borders
 
Thanks Peter,
Of course, I would be looping through the range one cell at a time with the
'BordersAround' code, but your suggestion would be more efficient I imagine.
--
David


"Peter T" wrote:

Hi David,

Since posting I also found:
Selection.BorderAround xlContinuous, xlHairline
works good too


That applies borders to the outside edges of the range but not the insides.
You originally asked

I would like to apply a hairline border to every cell in a range.


Only if your range comprises of one or more single cell areas would both
methods do same. So if you only want to do the outside, use "BorderAround",
otherwise the apply to the entire Borders collection in one go (assuming you
want same properties for all).

Regards,
Peter T


"David" wrote in message
...
Thanks Peter,
Works good,
Since posting I also found:
Selection.BorderAround xlContinuous, xlHairline
works good too
--
David


"Peter T" wrote:

Hi David

Sub test()
Dim bdrs As Borders

Set bdrs = Range("b3:e6").Borders
bdrs.LineStyle = xlContinuous
bdrs.Weight = xlHairline
bdrs.ColorIndex = 5

End Sub

Regards,
Peter T








All times are GMT +1. The time now is 09:20 PM.

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