LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Getting range of cells with specific text colour, then using in a COUNTIF formulae

Hi all,

I have a problem looking up some data from a large table.

I have a list of dates ranging throughout the year, and have used the
countif function to find the dates between certain periods, here I was
using the month of the year. The problem is that some of these dates
are in the font colour of red, and therefore need to be looked up and
referenced differently.

I have;

21/04/06
27/04/06
27/04/06
17/05/06
24/05/06
29/06/06
28/07/06
23/08/06
31/08/06
28/09/06
tbc

I have been trying to use the references for VBA colours in text from
Chips site;

Getting The Range Of Cells With A Specific Color

The following function will return a Range object consisting of those
cells in a range that have either an Interior (background) or Font of a
specified color. InRange is the range of cells to examine,
WhatColorIndex is the ColorIndex value to count, and OfText indicates
whether to return the ColorIndex of the Font (if True) or the Interior
(if False). This function uses the AddRange function to combine two
ranges into a single range, without the possible problems of the
Application.Union method. See AddRange, below, for more details about
this function.

Function RangeOfColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Range
'
' This function returns a Range of cells in InRange with a
' background color, or if OfText is True a font color,
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If OfText = True Then
If (Rng.Font.ColorIndex = WhatColorIndex) = True Then
Set RangeOfColor = AddRange(RangeOfColor, Rng)
End If
Else
If (Rng.Interior.ColorIndex = WhatColorIndex) = True Then
Set RangeOfColor = AddRange(RangeOfColor, Rng)
End If
End If
Next Rng

End Function

--and the add range VBA below;

Function AddRange(ByVal Range1 As Range, _
ByVal Range2 As Range) As Range
Dim Rng As Range

If Range1 Is Nothing Then
If Range2 Is Nothing Then
Set AddRange = Nothing
Else
Set AddRange = Range2
End If
Else
If Range2 Is Nothing Then
Set AddRange = Range1
Else
Set AddRange = Range1
For Each Rng In Range2
If Application.Intersect(Rng, Range1) Is Nothing Then
Set AddRange = Application.Union(AddRange, Rng)
End If
Next Rng
End If
End If

End Function

But I can't seem to get it to work properly with the referencing. this
being in one of the cells =rangeofcolor(B11:B21,3,TRUE)

Becasue I am guessing that I first need to get the reference of the
dates in red, and then use my countif formulae to find out how many of
the dates fall within my specific criteria. hence my countif formulae
of =COUNTIF(rangeofcolor(B11:B21,3,TRUE),"="&C3)

all I get is the #VALUE! Error.

Please please help, becasue I am really stuck with this one.

Cheers,

Dan

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count percentage of specific text in a range of cells kruggie2000 Excel Worksheet Functions 1 October 6th 08 05:59 PM
Using formulae to change the colour of cells in Excel [email protected] Excel Discussion (Misc queries) 7 February 7th 07 03:55 PM
Cell Colour based on text in Range of cells viewmaster[_2_] Excel Programming 2 March 3rd 06 03:53 AM
Cell Colour based on text in Range of cells viewmaster Excel Programming 1 March 3rd 06 03:42 AM
Countif for specific cells rather than a range ???? Renee - California Excel Worksheet Functions 5 May 27th 05 07:09 PM


All times are GMT +1. The time now is 01:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"