Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default border every other cell in range

I'm trying to write a macro that will apply a bottom border to every
other cell in a range. the macro only needs to work for horizontal
ranges, and not for vertical ones.

the closest i can get is the code below, but this only applys borders
to cells in odd columns. i need it to apply borders to every other
cell in a selection, regardless if it is even or odd.

Sub BotBorderOdd()
For Each cell In Selection
If Application.WorksheetFunction.Odd(cell.Column) = cell.Column
Then
oRange = oRange & "," & cell.Address
End If
Next cell
oRange = Mid(oRange, 2, Len(oRange) - 1)
Range(oRange).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub

Thanks for your help everyone!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default border every other cell in range

Sub BotBorderOdd()
Dim lFlag As Long
lFlag = Selection(1).Column Mod 2
For Each cell In Selection
If cell.Column Mod 2 < lFlag Then
oRange = oRange & "," & cell.Address

With cell.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End If
Next
End Sub


--
Regards,
Tom Ogilvy


"cass calculator" wrote:

I'm trying to write a macro that will apply a bottom border to every
other cell in a range. the macro only needs to work for horizontal
ranges, and not for vertical ones.

the closest i can get is the code below, but this only applys borders
to cells in odd columns. i need it to apply borders to every other
cell in a selection, regardless if it is even or odd.

Sub BotBorderOdd()
For Each cell In Selection
If Application.WorksheetFunction.Odd(cell.Column) = cell.Column
Then
oRange = oRange & "," & cell.Address
End If
Next cell
oRange = Mid(oRange, 2, Len(oRange) - 1)
Range(oRange).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub

Thanks for your help everyone!


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
Conditional add border in a range Hank Excel Discussion (Misc queries) 3 September 5th 09 12:24 AM
border on last cell of page effects border on beginning cell of ne GaryE Excel Discussion (Misc queries) 0 March 23rd 09 05:47 AM
border every other cell in range cass calculator Excel Programming 1 August 17th 06 05:15 PM
Changing the border of one cell s/n change the border of adjacent gjanssenmn Excel Discussion (Misc queries) 2 October 5th 05 08:35 PM
Apply Border to range when first cell has text. Bill Excel Programming 4 August 16th 05 08:46 PM


All times are GMT +1. The time now is 10:34 AM.

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

About Us

"It's about Microsoft Excel"