Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Count font colour in a cell

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Count font colour in a cell

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, "
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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Count font colour in a cell

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


" 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, "
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
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
textBox font colour the same as cell font colour???????? Sophie Excel Discussion (Misc queries) 4 February 13th 09 10:15 AM
Changing font colour depending on cell value RunRonnyRun Excel Worksheet Functions 1 October 27th 08 08:28 PM
formula to change font or cell colour Dave Excel Worksheet Functions 3 November 25th 07 08:25 PM
Count Font Colour Help Excel Discussion (Misc queries) 1 November 21st 07 09:44 PM
Format Cell Colour/Font with VBA Ren[_2_] Excel Programming 3 November 29th 05 05:58 AM


All times are GMT +1. The time now is 10:51 AM.

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"