AatB
Gebruiker
- Lid geworden
- 15 dec 2007
- Berichten
- 257
Geacht forum,
ik gebruik ondertstaande code om de kleuren van een cel te veranderen.
Het duurt circa 20 seconden om deze uit te voeren.
Weten jullie een snellere manier?
mvg,
Aat
ik gebruik ondertstaande code om de kleuren van een cel te veranderen.
Het duurt circa 20 seconden om deze uit te voeren.
Weten jullie een snellere manier?
mvg,
Aat
Code:
Sub CondFormatStart()
'Put colors in Cells
Dim r, c, acc, cpe, pe, cimp, rfs1, rfs2 As Range
Dim icolor As Integer
Dim fcolor As Integer
Dim fsize As Integer
Dim fbold As Variant
Dim FName As String
Dim LastRow As Integer
LastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
For Each r In ActiveSheet.Rows(2).SpecialCells(xlCellTypeConstants)
If r.Value = "Status" Then Set rfs1 = Range(Range(r.Address).Offset(1, 0).Address & ":" & Range(r.Address).Offset(LastRow, 0).Address)
If r.Value = "Acc Status" Then Set acc = Range(Range(r.Address).Offset(1, 0).Address & ":" & Range(r.Address).Offset(LastRow, 2).Address)
If r.Value = "CPE Status" Then Set cpe = Range(Range(r.Address).Offset(1, 0).Address & ":" & Range(r.Address).Offset(LastRow, 2).Address)
If r.Value = "PE Status" Then Set pe = Range(Range(r.Address).Offset(1, 0).Address & ":" & Range(r.Address).Offset(LastRow, 2).Address)
If r.Value = "CPE Imp Status" Then Set cimp = Range(Range(r.Address).Offset(1, 0).Address & ":" & Range(r.Address).Offset(LastRow, 2).Address)
If r.Value = "RFS Status" Then Set rfs2 = Range(Range(r.Address).Offset(1, 0).Address & ":" & Range(r.Address).Offset(LastRow, 2).Address)
Next r
ic = 35
acc.Interior.ColorIndex = 35
acc.Font.ColorIndex = 1
For Each c In acc
GoSub colors
Next c
ic = 20
cpe.Interior.ColorIndex = 20
cpe.Font.ColorIndex = 1
For Each c In cpe
GoSub colors
Next c
ic = 28
pe.Interior.ColorIndex = 28
pe.Font.ColorIndex = 1
For Each c In pe
GoSub colors
Next c
ic = 37
cimp.Interior.ColorIndex = 37
cimp.Font.ColorIndex = 1
For Each c In cimp
GoSub colors
Next c
ic = 0
rfs1.Interior.ColorIndex = 0
rfs1.Font.ColorIndex = 1
For Each c In rfs1
GoSub colors
Next c
ic = 39
rfs2.Interior.ColorIndex = 39
rfs2.Font.ColorIndex = 1
For Each c In rfs2
GoSub colors
Next c
Exit Sub
colors:
fcolor = 1
icolor = ic
If c.Value = "" Or _
InStr(LCase(c.Value), "n/a") Or _
InStr(LCase(c.Value), "cease") Or _
InStr(LCase(c.Value), "in progress") Or _
InStr(LCase(c.Value), "on hold") Then
GoTo NxtColors
End If
If InStr(LCase(c.Value), "delivered") Then
icolor = 4
ElseIf InStr(LCase(c.Value), "snf sent") Or _
InStr(LCase(c.Value), "cust confirmation") Or _
InStr(LCase(c.Value), "first billing") Or _
InStr(LCase(c.Value), "closing date") Or _
InStr(LCase(c.Value), "closed") Then
icolor = 36
ElseIf InStr(LCase(c.Value), "planned") Then
icolor = 23
ElseIf InStr(LCase(c.Value), "ordered") Then
icolor = 15
ElseIf InStr(LCase(c.Value), "jeopardy") Then
icolor = 45
ElseIf InStr(LCase(c.Value), "critical") Or _
InStr(LCase(c.Value), "failed") Or _
InStr(LCase(c.Value), "not on time") Then
icolor = 3
fcolor = 2
End If
NxtColors:
c.Interior.ColorIndex = icolor
c.Font.ColorIndex = fcolor
Return
End Sub