PDA

View Full Version : Solved: Check whether row is odd or even



Sir Babydum GBE
06-16-2006, 04:19 AM
Hi, in the following code (I've taken a section out for readability) I use a modified version of Jake's excellent multi-conditional formats code (found in the KB).
Private Sub Worksheet_Calculate()

Dim Cell As Range
Dim Rng1 As Range
Set Rng1 = Selection

On Error Resume Next
On Error GoTo 0
If Rng1 Is Nothing Then
Set Rng1 = Selection
Else
'Set Rng1 = Union(Range("B5:IQ50"), Rng1)
Set Rng1 = Selection
End If
For Each Cell In Rng1
Select Case Cell.Value
Case "N1"
Cell.Interior.ColorIndex = 40
Cell.Font.ColorIndex = xlColorIndexAutomatic
Case "N2"
Cell.Interior.ColorIndex = 43
Cell.Font.ColorIndex = xlColorIndexAutomatic
...
...
Case "S21"
Cell.Interior.ColorIndex = 15
Cell.Font.ColorIndex = 2
Case Else
Cell.Interior.ColorIndex = xlNone
Cell.Font.Bold = False
End Select
Next

End SubWhat I need to further modify is the "Case Else" section toward the end.

I need it to say "if all the above conditions are not met, then look at the row number - if it's odd, then do this, and if it's even, do that".

Any ideas how I say this in code?

Thanks

Killian
06-16-2006, 04:24 AM
If Cell.Row Mod 2 = 0 Then
'Even
Else
'odd
End If

Sir Babydum GBE
06-16-2006, 04:37 AM
If Cell.Row Mod 2 = 0 Then
'Even
Else
'odd
End If

Thanks! Works great!

BD