VBA Help with shading every other row

TkdKidSnake

Active Member
Joined
Nov 27, 2012
Messages
255
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am trying to make a spreadsheet easier to read, the sheet has many lines and varies in length. Column B will always have something in so this can be used to find the end of the data.

I am trying to shade in from B to S then miss T and shade U, the shading needs to start from row 5 however row 5 is essentially left alone and then the first shaded row would be row 6 see below:

Row 5 – no shading
Row 6 – Shaded
Row 7 – no shading
Row 8 – Shaded
Etc, Etc, Etc

I have recorded the following code to give you an idea of what I am trying to achieve.

Code:
Range("B6:S6,U6").Select
 Range("U6").Activate
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With
    
    Range("B8:S8,U8").Select
    Range("U8").Activate
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.599993896298105
        .PatternTintAndShade = 0
    End With


Any help you can provide would be greatly appreciated
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Code:
Public Sub ShadeEventRows()

Dim lastRow As Long
Dim thisRow As Long
Dim shadeRange As Range

lastRow = Cells(Rows.Count, "B").End(xlUp).Row
For thisRow = 6 To lastRow Step 2
    Set shadeRange = Application.Union(Range(Cells(thisRow, "B"), Cells(thisRow, "S")), Cells(thisRow, "U"))
    With shadeRange.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.6
        .PatternTintAndShade = 0
    End With
Next thisRow

End Sub

WBD
 
Upvote 0
This is excellent works a treat, many thanks

Code:
Public Sub ShadeEventRows()

Dim lastRow As Long
Dim thisRow As Long
Dim shadeRange As Range

lastRow = Cells(Rows.Count, "B").End(xlUp).Row
For thisRow = 6 To lastRow Step 2
    Set shadeRange = Application.Union(Range(Cells(thisRow, "B"), Cells(thisRow, "S")), Cells(thisRow, "U"))
    With shadeRange.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.6
        .PatternTintAndShade = 0
    End With
Next thisRow

End Sub

WBD
 
Upvote 0
Rich (BB code):
Public Sub ShadeEventRows()

Dim lastRow As Long
Dim thisRow As Long
Dim shadeRange As Range

lastRow = Cells(Rows.Count, "B").End(xlUp).Row
For thisRow = 6 To lastRow Step 2
    Set shadeRange = Application.Union(Range(Cells(thisRow, "B"), Cells(thisRow, "S")), Cells(thisRow, "U"))
    With shadeRange.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.6
        .PatternTintAndShade = 0
    End With
Next thisRow

End Sub
You can replace what I highlighted in red above with this shorter code snippet and it will also work...

Intersect(Range("A:S,U:U"), Rows(thisRow))
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top