Apply Alternate Shading to selected rows

A

andreashermle

Dear Experts:

Below macro is used to apply an alternate fill to selected cells.

I would like to get this macro changed to include also a specific fill
for a HEADER row (selected cells at the very top), ...
ie. the selected cells will also contain a header row. And these
header cells should get the following fill:
RGB(165, 165, 165), the font of this header is to be changed to bold
and font color is to be changed to white.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas


Sub AltShade_GreyRed()
Dim Counter As Integer

If MsgBox("Would you like to apply an alternate shading to
selected cells (grey/red)?", vbQuestion + vbYesNo, "Selected cells
alternate shading grey/red") = vbNo Then
Exit Sub
End If

'For every row in the current selection...
For Counter = 1 To Selection.Rows.Count
'If the row is an odd number (within the selection)...
If Counter Mod 2 = 1 Then
'Set the color to ...
Selection.Rows(Counter).Interior.Color = RGB(229, 229,
229)
'If the row is an even number (within the selection)
Else
Selection.Rows(Counter).Interior.Color = RGB(239, 211,
210)
End If
Next

End Sub
 
J

Jim Cone

Doesn't look Grey and Red to me.
Last three lines are new.
'---
Sub AltShade_GreyRed()
Dim Counter As Integer

If MsgBox("Would you like to apply an alternate shading to selected cells (grey/red)?", _
vbQuestion + vbYesNo, "Selected cells alternate shading grey/red") = vbNo Then
Exit Sub
End If

'For every row in the current selection...
For Counter = 1 To Selection.Rows.Count
'If the row is an odd number (within the selection)...
If Counter Mod 2 = 1 Then
'Set the color to ...
Selection.Rows(Counter).Interior.Color = RGB(229, 229, 229)
'If the row is an even number (within the selection)
Else
Selection.Rows(Counter).Interior.Color = RGB(239, 211, 210)
End If
Next
Selection.Rows(1).Interior.Color = RGB(165, 165, 165)
Selection.Rows(1).Font.Bold = True
Selection.Rows(1).Font.Color = vbWhite
End Sub
--
Jim Cone
Portland, Oregon USA
http://tinyurl.com/ShadeData
(Shade Data Rows Excel add-in)

..
..
..

"andreashermle" <[email protected]>
wrote in message
Dear Experts:

Below macro is used to apply an alternate fill to selected cells.

I would like to get this macro changed to include also a specific fill
for a HEADER row (selected cells at the very top), ...
ie. the selected cells will also contain a header row. And these
header cells should get the following fill:
RGB(165, 165, 165), the font of this header is to be changed to bold
and font color is to be changed to white.
Help is much appreciated. Thank you very much in advance.
Regards, Andreas


Sub AltShade_GreyRed()
Dim Counter As Integer

If MsgBox("Would you like to apply an alternate shading to
selected cells (grey/red)?", vbQuestion + vbYesNo, "Selected cells
alternate shading grey/red") = vbNo Then
Exit Sub
End If

'For every row in the current selection...
For Counter = 1 To Selection.Rows.Count
'If the row is an odd number (within the selection)...
If Counter Mod 2 = 1 Then
'Set the color to ...
Selection.Rows(Counter).Interior.Color = RGB(229, 229,
229)
'If the row is an even number (within the selection)
Else
Selection.Rows(Counter).Interior.Color = RGB(239, 211,
210)
End If
Next

End Sub
 
A

andreashermle

Doesn't look Grey and Red to me.
Last three lines are new.
'---
Sub AltShade_GreyRed()
 Dim Counter As Integer

 If MsgBox("Would you like to apply an alternate shading to selected cells (grey/red)?", _
    vbQuestion + vbYesNo, "Selected cells alternate shading grey/red") = vbNo Then
     Exit Sub
 End If

 'For every row in the current selection...
 For Counter = 1 To Selection.Rows.Count
     'If the row is an odd number (within the selection)...
     If Counter Mod 2 = 1 Then
         'Set the color to ...
         Selection.Rows(Counter).Interior.Color = RGB(229, 229, 229)
         'If the row is an even number (within the selection)
     Else
         Selection.Rows(Counter).Interior.Color = RGB(239, 211, 210)
     End If
 Next
 Selection.Rows(1).Interior.Color = RGB(165, 165, 165)
 Selection.Rows(1).Font.Bold = True
 Selection.Rows(1).Font.Color = vbWhite
End Sub
--
Jim Cone
Portland, Oregon  USAhttp://tinyurl.com/ShadeData
(Shade Data Rows Excel add-in)

.
.
.

"andreashermle" <[email protected]>
wrote in messageDear Experts:

Below macro is used to apply an alternate fill to selected cells.

I would like to get this macro changed to include also a specific fill
for a HEADER row (selected cells at the very top), ...
ie. the selected cells will also contain a header row. And these
header cells should get the following fill:
RGB(165, 165, 165), the font of this header is to be changed to bold
and font color is to be changed to white.
Help is much appreciated. Thank you very much in advance.
Regards, Andreas

Sub AltShade_GreyRed()
    Dim Counter As Integer

    If MsgBox("Would you like to apply an alternate shading to
selected cells (grey/red)?", vbQuestion + vbYesNo, "Selected cells
alternate shading grey/red") = vbNo Then
        Exit Sub
        End If

    'For every row in the current selection...
    For Counter = 1 To Selection.Rows.Count
        'If the row is an odd number (within the selection)...
        If Counter Mod 2 = 1 Then
            'Set the color to ...
            Selection.Rows(Counter).Interior.Color = RGB(229, 229,
229)
            'If the row is an even number (within the selection)
             Else
            Selection.Rows(Counter).Interior.Color = RGB(239, 211,
210)
        End If
    Next

End Sub

Hi Jim,

I was pretty sure that I already got back to you with a feedback.
Obviously not. Ok, now, thank you very much for your professional
support. Exactly what I wanted. Thank you very much. Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top