Colour Amendments Within Code

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,489
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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
59,892
Office Version
  1. 365
Platform
  1. Windows
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
 

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,489
Office Version
  1. 365
Platform
  1. Windows
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
59,892
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,136,283
Messages
5,674,831
Members
419,529
Latest member
TommasoP11

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
Top