Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default 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








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merged Cell Conditional Formatting Borders T Kirtley Excel Discussion (Misc queries) 2 June 1st 06 07:38 PM
Sometimes a cell will not allow formatting, like borders tom1 Excel Discussion (Misc queries) 0 February 3rd 06 07:33 PM
Can you apply split colour formatting to the same cell? Gazzypops Excel Discussion (Misc queries) 4 January 18th 06 06:36 PM
formatting won't apply to my cell with a formula Adrienne Excel Worksheet Functions 9 November 27th 05 05:44 PM
Cell Formatting or Borders Ryan D Excel Discussion (Misc queries) 7 March 14th 05 06:29 PM


All times are GMT +1. The time now is 12:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"