Counting by colour dilemma!!

S

Simon Lloyd

Hi All,

I have some code in my Auto_open that references a function to count b
colour only if a date exists which works fine, my problem is i hav
tried to replicate it but to count over a range only if the cel
contains text (or if easier could get it to look for a number entere
in the cell between 1 and 10) but if the cell contains #N/A to eithe
skip it or when counting delete it from the total.

Here's what i have so far, and the second half doesnt work!

simon



Sub Auto_open()

Dim ccount As Integer
Dim cccount As Variant
Application.DisplayAlerts = False
Application.DisplayFormulaBar = False

Range("B5").Select

ActiveCell.FormulaR1C1
"=COUNTBYCOLOR(R[9]C[-1]:R[484]C[-1],38,FALSE)"


Range("B7").Select
Range("d14").Select
ccount = Range("b5")
Range("B6").Select
ActiveCell.FormulaR1C1 = "=CntByColor(R[8]C[2]:R[485]C[33],38,FALSE)"
Range("B7").Select
Range("d14").Select
cccount = Range("B6")
Worksheets("holidays").Visible = True
Worksheets("Holiday Count").Visible = True
Worksheets("Xtra's & Count").Visible = True
Sheets("holidays").Activate
MsgBox "There Are " & ccount & " Holiday Clashes" & Chr(13) & " Ther
Have Been " & cccount & " accomodations", vbOKOnly, "Clash Count"


End Sub



Function CountByColor(InRange As Range, WhatColorIndex As Integer
Optional OfText As Boolean = False) As Long
Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If IsDate(Rng) Then
If OfText = True Then
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
End If
Next Rng

End Function

Function CntByColor(InRange As Range, WhatColorIndex As Integer
Optional OfText As Boolean = False) As Long
Dim Rng As Range
Dim cccount As Integer
Application.Volatile True
Range("D14:AI491") = Rng
For Each Rng In InRange.Cells
If OfText = True Then
If ActiveCell.Text = "#N/A" Then
Range("B6").Value = Range("B6").Value - 1
CntByColor = CntByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CntByColor = CntByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
End If
Next Rng

End Functio
 
C

crispbd

Function CntByColor(InRange As Range, WhatColorIndex As Integer
Optional OfText As Boolean = False) As Long
Dim Rng As Range
Dim cccount As Integer
Application.Volatile True
Range("D14:AI491") = Rng
For Each Rng In InRange.Cells
If OfText = True Then
IF APPLICATION.WORKSHEETFUNCTION.ISNA(ACTIVECELL.VALUE) THE
Range("B6").Value = Range("B6").Value - 1
CntByColor = CntByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CntByColor = CntByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
End If
Next Rng

End Functio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top