Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Use VBA to shade every 3 rows (banding)

I've seen ways to do this with conditional formatting (http://
www.cpearson.com/excel/banding.aspx), but I'd like to do it with VBA.

How do I modify the below macro to shade alternate groups of 3 rows?
Instead of every other row...

Sub HighlightAltRows()

Selection.Interior.ColorIndex = xlNone

Dim Counter As Integer

For Counter = 1 To Selection.Rows.Count
If Counter Mod 2 = 0 Then
Selection.Rows(Counter).Interior.ColorIndex = 54
End If
Next
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 896
Default Use VBA to shade every 3 rows (banding)

replace

If Counter Mod 2 = 0 Then

with

If Counter Mod 3 = 0 Then



On 2 Cze, 13:48, MikeS wrote:
I've seen ways to do this with conditional formatting (http://www.cpearson.com/excel/banding.aspx), but I'd like to do it with VBA.

How do I modify the below macro to shade alternate groups of 3 rows?
Instead of every other row...

Sub HighlightAltRows()

* * Selection.Interior.ColorIndex = xlNone

* * Dim Counter As Integer

* * For Counter = 1 To Selection.Rows.Count
* * * * If Counter Mod 2 = 0 Then
* * * * * * Selection.Rows(Counter).Interior.ColorIndex = 54
* * * * End If
* * Next
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Use VBA to shade every 3 rows (banding)

On Jun 2, 7:56*am, Jarek Kujawa wrote:
replace

* * * * If Counter Mod 2 = 0 Then

with

* * * * If Counter Mod 3 = 0 Then

On 2 Cze, 13:48, MikeS wrote:

I've seen ways to do this with conditional formatting (http://www.cpearson.com/excel/banding.aspx), but I'd like to do it with VBA.


How do I modify the below macro to shade alternate groups of 3 rows?
Instead of every other row...


Sub HighlightAltRows()


* * Selection.Interior.ColorIndex = xlNone


* * Dim Counter As Integer


* * For Counter = 1 To Selection.Rows.Count
* * * * If Counter Mod 2 = 0 Then
* * * * * * Selection.Rows(Counter).Interior.ColorIndex = 54
* * * * End If
* * Next
End Sub




that's not quite what I'm looking for. Let me explain better.

If I select a group of cells (A1:M12), I want:

rows 1-3 = no shade
rows 4-6 = shaded
rows 7-9 = no shade
rows 10-12 = shaded

thanks!
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 896
Default Use VBA to shade every 3 rows (banding)

pls click YES if it helped

Sub HighlightAltRows()

Selection.Interior.ColorIndex = xlNone

Dim Counter As Integer

For Counter = 1 To Selection.Rows.Count Step 3
If Counter Mod 2 = 0 Then
Range(Selection.Rows(Counter), Selection.Rows(Counter +
2)).Interior.ColorIndex = 54
End If
Next
End Sub


On 2 Cze, 14:12, MikeS wrote:
On Jun 2, 7:56*am, Jarek Kujawa wrote:





replace


* * * * If Counter Mod 2 = 0 Then


with


* * * * If Counter Mod 3 = 0 Then


On 2 Cze, 13:48, MikeS wrote:


I've seen ways to do this with conditional formatting (http://www.cpearson.com/excel/banding.aspx), but I'd like to do it with VBA.


How do I modify the below macro to shade alternate groups of 3 rows?
Instead of every other row...


Sub HighlightAltRows()


* * Selection.Interior.ColorIndex = xlNone


* * Dim Counter As Integer


* * For Counter = 1 To Selection.Rows.Count
* * * * If Counter Mod 2 = 0 Then
* * * * * * Selection.Rows(Counter).Interior.ColorIndex = 54
* * * * End If
* * Next
End Sub


that's not quite what I'm looking for. *Let me explain better.

If I select a group of cells (A1:M12), I want:

rows 1-3 = no shade
rows 4-6 = shaded
rows 7-9 = no shade
rows 10-12 = shaded

thanks!- Ukryj cytowany tekst -

- Pokaż cytowany tekst -


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Use VBA to shade every 3 rows (banding)

'Replace the If condition with
If (Counter + 2) \ 3 Mod 2 = 0 Then


If this post helps click Yes
---------------
Jacob Skaria


"MikeS" wrote:

On Jun 2, 7:56 am, Jarek Kujawa wrote:
replace

If Counter Mod 2 = 0 Then

with

If Counter Mod 3 = 0 Then

On 2 Cze, 13:48, MikeS wrote:

I've seen ways to do this with conditional formatting (http://www.cpearson.com/excel/banding.aspx), but I'd like to do it with VBA.


How do I modify the below macro to shade alternate groups of 3 rows?
Instead of every other row...


Sub HighlightAltRows()


Selection.Interior.ColorIndex = xlNone


Dim Counter As Integer


For Counter = 1 To Selection.Rows.Count
If Counter Mod 2 = 0 Then
Selection.Rows(Counter).Interior.ColorIndex = 54
End If
Next
End Sub




that's not quite what I'm looking for. Let me explain better.

If I select a group of cells (A1:M12), I want:

rows 1-3 = no shade
rows 4-6 = shaded
rows 7-9 = no shade
rows 10-12 = shaded

thanks!



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Use VBA to shade every 3 rows (banding)

On Jun 2, 8:22*am, Jarek Kujawa wrote:
pls click YES if it helped

Sub HighlightAltRows()

* * Selection.Interior.ColorIndex = xlNone

* * Dim Counter As Integer

* * For Counter = 1 To Selection.Rows.Count Step 3
* * * * If Counter Mod 2 = 0 Then
* * * * * * Range(Selection.Rows(Counter), Selection.Rows(Counter +
2)).Interior.ColorIndex = 54
* * * * End If
* * Next
End Sub

On 2 Cze, 14:12, MikeS wrote:

On Jun 2, 7:56*am, Jarek Kujawa wrote:


replace


* * * * If Counter Mod 2 = 0 Then


with


* * * * If Counter Mod 3 = 0 Then


On 2 Cze, 13:48, MikeS wrote:


I've seen ways to do this with conditional formatting (http://www.cpearson.com/excel/banding.aspx), but I'd like to do it with VBA.


How do I modify the below macro to shade alternate groups of 3 rows?
Instead of every other row...


Sub HighlightAltRows()


* * Selection.Interior.ColorIndex = xlNone


* * Dim Counter As Integer


* * For Counter = 1 To Selection.Rows.Count
* * * * If Counter Mod 2 = 0 Then
* * * * * * Selection.Rows(Counter).Interior.ColorIndex = 54
* * * * End If
* * Next
End Sub


that's not quite what I'm looking for. *Let me explain better.


If I select a group of cells (A1:M12), I want:


rows 1-3 = no shade
rows 4-6 = shaded
rows 7-9 = no shade
rows 10-12 = shaded


thanks!- Ukryj cytowany tekst -


- Pokaż cytowany tekst -




that worked! thanks!
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
Shade even rows in a sheet CB Excel Discussion (Misc queries) 2 December 9th 08 09:16 PM
how to shade every other 5 rows chiechka New Users to Excel 7 April 30th 07 02:02 PM
shade hidden rows TJ Excel Discussion (Misc queries) 6 January 19th 06 02:43 AM
shade rows Manohar Excel Discussion (Misc queries) 2 March 31st 05 07:17 PM
shade rows Manny Excel Discussion (Misc queries) 2 March 31st 05 06:56 PM


All times are GMT +1. The time now is 02:59 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"