VBA Color for Alternating rows

Kiloelectronvolt

Board Regular
Joined
Oct 5, 2015
Messages
81
Office Version
  1. 365
Platform
  1. Windows
Hi All, I found this code online, but I can't stand the color options in the index. I'm a noob and can't get it to switch to RGB format. Can someone please help? Thanks!

VBA Code:
Sub ShadeRows()
'Updateby20140529
Dim Rng As Range
Dim WorkRng As Range
Dim shadeIt As Boolean
shadeIt = True
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng.Rows
    If Not Rng.EntireRow.Hidden Then
        Rng.Interior.ColorIndex = _
        IIf(shadeIt, 15, xlNone)
        shadeIt = Not (shadeIt)
    End If
Next
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You can use rgb like
VBA Code:
Rng.Interior.Color = IIf(shadeIt, RGB(255, 0, 0), RGB(0, 0, 255))
 
Upvote 0
How about this?

VBA Code:
Sub ShadeRows()
'Updateby20140529
Dim Rng As Range
Dim WorkRng As Range
Dim shadeIt As Boolean
shadeIt = True
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng.Rows
    If Not Rng.EntireRow.Hidden Then
        Rng.Interior.Color = _
        IIf(shadeIt, RGB(225, 25, 220), xlNone)
        shadeIt = Not (shadeIt)
    End If
Next
End Sub
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,412
Messages
6,119,369
Members
448,888
Latest member
Arle8907

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