asked on
ASKER
Option Explicit
Option Base 0
Sub Colour_Numbers()
Dim i As Long
Dim j As Long
Dim xLast_Row As Long
Dim xArray1 As Variant
Dim xArray2 As Variant
Dim xArray3 As Variant
Dim Xall As Variant
Dim StartTime As Variant
Dim xNumbers As Worksheet
StartTime = Timer
Set xNumbers = Sheets("Numbers")
xLast_Row = xNumbers.UsedRange.Cells(1, 1).Row + xNumbers.UsedRange.Rows.Count - 1
If xLast_Row < 3 Then
MsgBox ("No data found in the ""Numbers"" Sheet - run cancelled.")
Exit Sub
End If
xArray1 = [Update!B4:B25]
xArray2 = [Update!C4:C25]
xArray3 = [Update!D4:D25]
Application.ScreenUpdating = False
'Set default to first category...
xNumbers.Range("B3:G" & xLast_Row).Interior.ColorIndex = 3
xNumbers.Range("B3:G" & xLast_Row).Font.ColorIndex = 2
xNumbers.Range("B3:G" & xLast_Row).Font.Bold = True
Xall = xNumbers.Range("B1:G" & xLast_Row)
For i = 3 To xLast_Row
For j = 1 To 6
Select Case Xall(i, j)
Case xArray1(1, 1), xArray1(2, 1), xArray1(3, 1), xArray1(4, 1), xArray1(5, 1), xArray1(6, 1), xArray1(7, 1), xArray1(8, 1), xArray1(9, 1), xArray1(10, 1) _
, xArray1(11, 1), xArray1(12, 1), xArray1(13, 1), xArray1(14, 1), xArray1(15, 1), xArray1(16, 1), xArray1(17, 1), xArray1(18, 1), xArray1(19, 1), xArray1(20, 1) _
, xArray1(21, 1), xArray1(22, 1)
' Nothing to do as this is the default.
Case xArray2(1, 1), xArray2(2, 1), xArray2(3, 1), xArray2(4, 1), xArray2(5, 1), xArray2(6, 1), xArray2(7, 1), xArray2(8, 1), xArray2(9, 1), xArray2(10, 1) _
, xArray2(11, 1), xArray2(12, 1), xArray2(13, 1), xArray2(14, 1), xArray2(15, 1), xArray2(16, 1), xArray2(17, 1), xArray2(18, 1), xArray2(19, 1), xArray2(20, 1) _
, xArray2(21, 1), xArray2(22, 1)
xNumbers.Cells(i, j + 1).Interior.ColorIndex = 4
xNumbers.Cells(i, j + 1).Font.ColorIndex = 1
Case xArray3(1, 1), xArray3(2, 1), xArray3(3, 1), xArray3(4, 1), xArray3(5, 1), xArray3(6, 1), xArray3(7, 1), xArray3(8, 1), xArray3(9, 1), xArray3(10, 1) _
, xArray3(11, 1), xArray3(12, 1), xArray3(13, 1), xArray3(14, 1), xArray3(15, 1), xArray3(16, 1), xArray3(17, 1), xArray3(18, 1), xArray3(19, 1), xArray3(20, 1) _
, xArray3(21, 1), xArray3(22, 1)
xNumbers.Cells(i, j + 1).Interior.ColorIndex = 14
Case Else
xNumbers.Cells(i, j + 1).Interior.ColorIndex = xlNone
xNumbers.Cells(i, j + 1).Font.ColorIndex = 1
xNumbers.Cells(i, j + 1).Font.Bold = False
End Select
Next
Next
Application.ScreenUpdating = True
Debug.Print "Processed " & i - 2 & " rows of " & xLast_Row & " - " & Format(Timer - StartTime, "000") & " seconds."
MsgBox ("Processed " & i - 2 & " rows of " & xLast_Row & " - " & Format(Timer - StartTime, "000") & " seconds.")
End Sub
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
The 3 numbercolumns on Update are named Group1 for B4:B25, Group2 for C4:C25 and Group3 for D4:D25.
The conditional formula for first colour is =ISERROR(MATCH(B3,Group1,0
Similar for the other 2.
See attached file, not sure colours are excactly match, downsized to 30 rows, copy B3 to your actual file and change the conditional range to column G and row 142509