Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default bottom border every second 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: 644
Default bottom border every second cell in range

Try this:
Sub BotBorderOdd()
Dim i as long
i = 1
For Each cell In Selection
If i mod 2 = 0 Then
With Cell.Bordes(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End If
i = i + 1
Next cell
End Sub


Charles

Uses
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!


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

Charles showed you how to do it for even columns instead of ODD.

If you want to do it relative to the selection,

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

underlines the 2nd cell and each subsequent cell.

if you want to start with the first and each second cell from there, change
< to = in the conditional clause.

--
Regards,
Tom Ogilvy


"Die_Another_Day" wrote:

Try this:
Sub BotBorderOdd()
Dim i as long
i = 1
For Each cell In Selection
If i mod 2 = 0 Then
With Cell.Bordes(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End If
i = i + 1
Next cell
End Sub


Charles

Uses
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!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default bottom border every second cell in range

You guys are so awesome. Thank you very much!


Tom Ogilvy wrote:
Charles showed you how to do it for even columns instead of ODD.

If you want to do it relative to the selection,

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

underlines the 2nd cell and each subsequent cell.

if you want to start with the first and each second cell from there, change
< to = in the conditional clause.

--
Regards,
Tom Ogilvy


"Die_Another_Day" wrote:

Try this:
Sub BotBorderOdd()
Dim i as long
i = 1
For Each cell In Selection
If i mod 2 = 0 Then
With Cell.Bordes(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End If
i = i + 1
Next cell
End Sub


Charles

Uses
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
How do I border a bottom half of a cell in excel Matsnake Excel Discussion (Misc queries) 3 December 27th 07 02:04 AM
Border at bottom of worksheet Terry Excel Discussion (Misc queries) 3 May 17th 07 08:51 PM
Text extending beyond the right and bottom border of cell LTeeple Excel Discussion (Misc queries) 5 April 5th 07 10:42 AM
Repeat bottom Border Scafidel Excel Discussion (Misc queries) 3 August 29th 06 05:37 AM
only last cell on page to have bottom border (cell area outline) Wiggum Excel Worksheet Functions 1 April 29th 05 03:53 PM


All times are GMT +1. The time now is 03:33 PM.

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"