asked on
ASKER
ASKER
Sub ApplyColour()
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
Dim r As Range
Set Baserange = Range("B3:G3")
For Each r In Baserange.Cells
If Not d.Exists(r.Value) Then
d.Add r.Value, r.Interior.Color
End If
Next r
For Each r In Selection.Cells
If d.Exists(r.Value) Then
If d.Item(r.Value) = 16777215 Then
r.Interior.Pattern = xlNone
Else
r.Interior.Color = d.Item(r.Value)
End If
End If
Next r
End Sub
ASKER
ASKER
ASKER
ASKER
Sub Numbers()
Dim MyCell As Range, rgHighlight As Range, rg1 As Range, rg2 As Range, rg3 As Range, rg4 As Range, rg5 As Range, rg6 As Range
Application.ScreenUpdating = False
Set rg1 = [B3] 'Highlight values that match these cells
Set rg2 = [C3] 'Highlight values that match these cells in
Set rg3 = [D3] 'Highlight values that match these cells in
Set rg4 = [E3] 'Highlight values that match these cells in
Set rg5 = [F3] 'Highlight values that match these cells in
Set rg6 = [G3] 'Highlight Mega Ball value in dark cyan
'Set rgHighlight = Selection
Set rgHighlight = [B2:F1000]
'Loop using a For Each…Next in selection
For Each MyCell In Selection
If Application.CountIf(rg1, MyCell) > 0 Then
'Set the No 1 cell background color to First Number
MyCell.Interior.ColorIndex = 3
MyCell.Font.ColorIndex = 2
MyCell.Font.Bold = True
ElseIf Application.CountIf(rg2, MyCell) > 0 Then
'Set the No 2 cell background color to second Number
MyCell.Interior.ColorIndex = 4
MyCell.Font.ColorIndex = 2
MyCell.Font.Bold = True
ElseIf Application.CountIf(rg3, MyCell) > 0 Then
'Set the No 3 cell background color to Third Number
MyCell.Interior.ColorIndex = 14 'Cyan is 8, yellow is 6 (but hard to read)
MyCell.Font.ColorIndex = 2
MyCell.Font.Bold = True
ElseIf Application.CountIf(rg4, MyCell) > 0 Then
'Set the No 2 cell background color to Fourth Number
MyCell.Interior.ColorIndex = 12
MyCell.Font.ColorIndex = 2
MyCell.Font.Bold = True
ElseIf Application.CountIf(rg5, MyCell) > 0 Then
'Set the No 3 cell background color to Fifth Number
MyCell.Interior.ColorIndex = 13
MyCell.Font.ColorIndex = 2
MyCell.Font.Bold = True
'ElseIf Application.CountIf(rg6, MyCell) > 0 Then
'Set the No 3 cell background color to Sixth Number
'MyCell.Interior.ColorIndex = 11
'MyCell.Font.ColorIndex = 2
'MyCell.Font.Bold = True
Else
'Set other background color to white with black letters
MyCell.Interior.ColorIndex = xlNone
MyCell.Font.ColorIndex = 1
MyCell.Font.Bold = False
'Else
'Set the cell background color to blue
'MyCell.Interior.ColorIndex = 9
'MyCell.Font.ColorIndex = 2
'MyCell.Font.Bold = True
End If
Next
Application.ScreenUpdating = True
End Sub
Sub ApplyColour()
Application.ScreenUpdating = False
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
Dim r As Range, c As Range
Dim BaseColours
BaseColours = Array(3, 4, 14, 12, 13, 11)
Set Baserange = Range("B3:G3")
For Each r In Baserange.Cells
If Not d.Exists(r.Value) Then
x = x + 1
d.Add r.Value, x
End If
Next r
Set c = [B2:G1000]
c.Interior.ColorIndex = xlNone
c.Font.ColorIndex = 1
c.Font.Bold = False
For Each r In c.Cells
If d.Exists(r.Value) Then
r.Interior.ColorIndex = BaseColours(d.Item(r.Value) - 1)
r.Font.ColorIndex = 2
r.Font.Bold = True
End If
Next r
Application.ScreenUpdating = True
End Sub
ASKER
Option Explicit
Sub ApplyColour()
Dim x As Long
Dim d As Object
Set d = CreateObject("Scripting.Dictionary")
Dim r As Range, c As Range
Dim BaseColours
BaseColours = Array(3, 4, 14, 12, 13, 11)
Dim BaseRange As Range
Set BaseRange = Range("B3:G3")
For Each r In BaseRange.Cells
If Not d.Exists(r.Value) Then
x = x + 1
d.Add r.Value, x
End If
Next r
Set c = Application.InputBox(Prompt:="Please Select Range", Title:="Range Select", Type:=8)
Application.ScreenUpdating = False
c.Interior.ColorIndex = xlNone
c.Font.ColorIndex = 1
c.Font.Bold = False
For Each r In c.Cells
If d.Exists(r.Value) Then
r.Interior.ColorIndex = BaseColours(d.Item(r.Value) - 1)
r.Font.ColorIndex = 2
r.Font.Bold = True
End If
Next r
Application.ScreenUpdating = True
End Sub
ASKER
ASKER
ASKER
ASKER
ASKER
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY
but what would really help would be a sample mock workbook.
This, with some lines of explanation, would help tailor the solution to your needs.
ATB
Steve.