Need help with Macro's and Shading
Thanks macropod.
I tried to copy and paste that in and try it but I got a compile error:
Expected End Sub. I'm sure what that means but do I need to add in some
other values or info to that formula? Thanks for your help.
"macropod" wrote:
Hi Madhart,
Try this in the relevant worksheet module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Line As Range
Dim oCel As Range
With Target
If .Row 7 And .Row < 95 And .Column < 19 Then
Set Line = Range(Cells(.Row, 1), Cells(.Row, 19))
For Each oCel In Line.Cells
With oCel.Interior
If .ColorIndex < 2 Then
If .Row Mod 2 = 0 Then
.ColorIndex = 24
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
Else
.ColorIndex = 22
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End If
End If
End With
Next
End If
End With
End Sub
You might want to change .ColorIndex = 22 to some other value.
--
Cheers
macropod
[MVP - Microsoft Word]
"Madhart" wrote in message ...
Sorry If I'm posting in the wrong place.
I'm trying to set up some shading macro's or rules for an excel page (excel
2003) and running into a little difficulty. I set up a macro to put in a
light shading to make everything easy on the eyes every even number row:
Range( _
"A8:S8,[through],A94:S94" _
).Select
With Selection.Interior
.ColorIndex = 24
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Range("G4:M4").Select
End Sub
I also created one to remove the shading.
however, I also have a macro to add a mandatory and needed shading of:
With Selection.Interior
.ColorIndex = 2
.Pattern = xlLightUp
.PatternColorIndex = xlAutomatic
End With
End Sub
This shading will be in random cells and change day by day but needs to stay.
My question is: Is there any way to create an exception so that if there
are any cells that have the .ColorIndex = 2/.Pattern = xlLightUp shading in
them then the other shadings/or removal won't overwrite them but instead
leave them and continue filling in the rest of the cells?
Thanks :)
|