Colour Amendments Within Code

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,748
Office Version
  1. 365
Platform
  1. Windows
I have the code below that when data matches in C then it colours the row then does the same again on next rows in C and so on then starts again with the colouring. Could the colours be changed please as some are too bright on some. So instead of the vb array what needs changing so it uses .Interior.ColorIndex = 3 or 6 for example on each colour? Thanks



Code:
Sub ColourTheRows()
    ' This colours in the rows that have the same value in column c
    Application.ScreenUpdating = False
    Dim colors As Variant, SameData As String, i As Long, j As Integer
    colors = Array(vbRed, vbGreen, vbYellow, vbBlue, vbWhite, vbMagenta, vbCyan)
    SameData = Cells(1, 3)
    For i = 1 To Cells(Rows.Count, 3).End(xlUp).Row
        If Cells(i, 3) <> SameData Then
            j = j + 1
            SameData = Cells(i, 3)
        End If
        If j = 7 Then
            j = 0
        End If
        Rows(i).Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = colors(j)
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    Next i
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
How about
VBA Code:
Sub ColourTheRows()
    ' This colours in the rows that have the same value in column c
    Application.ScreenUpdating = False
    Dim colors As Variant, SameData As String, i As Long, j As Integer
    colors = Array(3, 6, 13, 35, 43, 19, 54)
    SameData = Cells(1, 3)
    For i = 1 To Cells(Rows.Count, 3).End(xlUp).Row
        If Cells(i, 3) <> SameData Then
            j = j + 1
            SameData = Cells(i, 3)
        End If
        If j = 7 Then
            j = 0
        End If
        Rows(i).Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ColorIndex = colors(j)
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    Next i
    Application.ScreenUpdating = True
End Sub
Just change the numbers in the array to suit
 
Upvote 0
How about
VBA Code:
Sub ColourTheRows()
    ' This colours in the rows that have the same value in column c
    Application.ScreenUpdating = False
    Dim colors As Variant, SameData As String, i As Long, j As Integer
    colors = Array(3, 6, 13, 35, 43, 19, 54)
    SameData = Cells(1, 3)
    For i = 1 To Cells(Rows.Count, 3).End(xlUp).Row
        If Cells(i, 3) <> SameData Then
            j = j + 1
            SameData = Cells(i, 3)
        End If
        If j = 7 Then
            j = 0
        End If
        Rows(i).Select
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ColorIndex = colors(j)
            .TintAndShade = 0
            .PatternTintAndShade = 0
        End With
    Next i
    Application.ScreenUpdating = True
End Sub
Just change the numbers in the array to suit
Perfect. Thanks Fluff.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,924
Members
448,533
Latest member
thietbibeboiwasaco

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