Theme color accent to RGB

Afro_Cookie

Board Regular
Joined
Mar 17, 2020
Messages
103
Office Version
  1. 365
Platform
  1. Windows
I have some code that helps me highlight unique cells as yellow using VBA. I did this to eliminate my conditional formatting duplicating itself and causing issues in my worksheets. The issue is I want to use RGB colours instead of Themeaccentcolours

Can some of you more experienced people please help me modify that specific part of my code so I can use RGB(0,255,0) in place of xlThemeColorAccent2

VBA Code:
Option Explicit

Public Sub markunique()
Dim iColour As Integer
Dim rng As Range
Dim rngCell As Variant
Dim LR As Long
Dim vVal

LR = Cells(Rows.Count, "B").End(xlUp).Row

Set rng = Range("B6:B" & LR)
iColour = xlThemeColorAccent2

rng.FormatConditions.Delete

For Each rngCell In rng.Cells
    vVal = rngCell.Text
    If (WorksheetFunction.CountIf(Range("B6:B" & rngCell.Row), vVal) = 1) Then
        rngCell.Interior.ColorIndex = iColour
    Else
        rngCell.Interior.Pattern = xlNone
    End If
    
Next
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi there

Maybe try..

VBA Code:
Option Explicit

Public Sub markunique()
Dim iColour As Long
Dim rng As Range
Dim rngCell As Variant
Dim LR As Long
Dim vVal

LR = Cells(Rows.Count, "B").End(xlUp).Row

Set rng = Range("B6:B" & LR)
iColour = RGB(0, 255, 0)

rng.FormatConditions.Delete

For Each rngCell In rng.Cells
    vVal = rngCell.Text
    If (WorksheetFunction.CountIf(Range("B6:B" & rngCell.Row), vVal) = 1) Then
        rngCell.Interior.Color = iColour
    Else
        rngCell.Interior.Pattern = xlNone
    End If
    
Next
End Sub
 
Upvote 0
Solution
Hi there

Maybe try..

VBA Code:
Option Explicit

Public Sub markunique()
Dim iColour As Long
Dim rng As Range
Dim rngCell As Variant
Dim LR As Long
Dim vVal

LR = Cells(Rows.Count, "B").End(xlUp).Row

Set rng = Range("B6:B" & LR)
iColour = RGB(0, 255, 0)

rng.FormatConditions.Delete

For Each rngCell In rng.Cells
    vVal = rngCell.Text
    If (WorksheetFunction.CountIf(Range("B6:B" & rngCell.Row), vVal) = 1) Then
        rngCell.Interior.Color = iColour
    Else
        rngCell.Interior.Pattern = xlNone
    End If
   
Next
End Sub
An Error is generated and the below line of code is highlighted.

Run-time error '9':
Subscript out of range

VBA Code:
rngCell.Interior.ColorIndex = iColour
 
Upvote 0
An Error is generated and the below line of code is highlighted.

Run-time error '9':
Subscript out of range

VBA Code:
rngCell.Interior.ColorIndex = iColour
Did you copy the code exactly as provided?

That line has been updated to

VBA Code:
rngCell.Interior.Color = iColour

in the code provided...
 
Upvote 0
Did you copy the code exactly as provided?

That line has been updated to

VBA Code:
rngCell.Interior.Color = iColour

in the code provided...
i didn't. sorry. I missed that modification.

I've modified that line and now it works perfectly. Thank you for the quick and supportive responses.
 
Upvote 0
i didn't. sorry. I missed that modification.

I've modified that line and now it works perfectly. Thank you for the quick and supportive responses.
No problem... glad we could help and thanks for the feedback :cool:
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

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