PC Review


Reply
Thread Tools Rate Thread

Count font colour in a cell

 
 
kabimeister@googlemail.com
Guest
Posts: n/a
 
      3rd Jul 2008
I have a worksheet with entries of different font colours. Is there a
way to count the number occurences of a particular font colour within
the string in each cell?
For example:

cell a1 has the entry 'Bluered'. The first four charcters are in blue
font (41) and the last 3 in red (3).
I want a way to count how many of the text characters are blue = 4.

I hope this makes sense.

Thanks.
 
Reply With Quote
 
 
 
 
paul.robinson@it-tallaght.ie
Guest
Posts: n/a
 
      3rd Jul 2008
Hi
This will count blues

Function CountBlue(StringRange As Range) As Long
Dim i As Long, Temp As Long

Temp = 0
If Trim(StringRange.Value) <> "" Then
For i = 1 To Len(StringRange.Value)
If StringRange.Characters(Start:=i, Length:=1).Font.ColorIndex = 5
Then
Temp = Temp + 1
End If
Next i
End If
CountBlue = Temp
End Function

You can use it in a worksheet as
=CountBlue(A1)

to count blue characters in A1
regards
Paul

On Jul 3, 2:49*pm, "kabimeis...@googlemail.com"
<kabimeis...@googlemail.com> wrote:
> I have a worksheet with entries of different font colours. *Is there a
> way to count the number occurences of a particular font colour within
> the string in each cell?
> For example:
>
> cell a1 has the entry 'Bluered'. The first four charcters are in blue
> font (41) and the last 3 in red (3).
> I want a way to count how many of the text characters are blue = 4.
>
> I hope this makes sense.
>
> Thanks.


 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      4th Jul 2008
Function CountByColor(InRange As Range, _
WhatColorIndex As Integer, _
Optional OfText As Boolean = False) As Long
'
' This function return the number 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
CountByColor = CountByColor - _
(Rng.Font.ColorIndex = WhatColorIndex)
Else
CountByColor = CountByColor - _
(Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng

End Function

Call the function as such:
=CountByColor(A1:E11,3)

Before the comma is the range that you are counting and after the comma is
the color (3=red).
See this for more info.
http://www.mvps.org/dmcritchie/excel/colors.htm



Regards,
Ryan---

--
RyGuy


"(E-Mail Removed)" wrote:

> Hi
> This will count blues
>
> Function CountBlue(StringRange As Range) As Long
> Dim i As Long, Temp As Long
>
> Temp = 0
> If Trim(StringRange.Value) <> "" Then
> For i = 1 To Len(StringRange.Value)
> If StringRange.Characters(Start:=i, Length:=1).Font.ColorIndex = 5
> Then
> Temp = Temp + 1
> End If
> Next i
> End If
> CountBlue = Temp
> End Function
>
> You can use it in a worksheet as
> =CountBlue(A1)
>
> to count blue characters in A1
> regards
> Paul
>
> On Jul 3, 2:49 pm, "kabimeis...@googlemail.com"
> <kabimeis...@googlemail.com> wrote:
> > I have a worksheet with entries of different font colours. Is there a
> > way to count the number occurences of a particular font colour within
> > the string in each cell?
> > For example:
> >
> > cell a1 has the entry 'Bluered'. The first four charcters are in blue
> > font (41) and the last 3 in red (3).
> > I want a way to count how many of the text characters are blue = 4.
> >
> > I hope this makes sense.
> >
> > Thanks.

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
textBox font colour the same as cell font colour???????? Sophie Microsoft Excel Misc 4 13th Feb 2009 10:15 AM
Count Font Colour =?Utf-8?B?SGVscA==?= Microsoft Excel Misc 1 21st Nov 2007 09:44 PM
Count Filled colour in cell in given range sizz1@hotmail.com Microsoft Excel Programming 4 16th May 2006 11:24 AM
Format Cell Colour/Font with VBA Ren Microsoft Excel Programming 3 29th Nov 2005 05:58 AM
Formula to count Cell colour. themax16 Microsoft Excel Misc 3 29th May 2005 01:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:14 AM.