User defined function help

easybpw

Active Member
Joined
Sep 30, 2003
Messages
406
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
I have a sumbold UDF that works like it should. What I now would like is a function that works similarly. I would like a countabold function. What I would like to do is count the number of cells that have TEXT in it that is bold. I know in order to count text I must use the counta function instead of just the count function. My macro looks like this:

Function COUNTABOLD(myRange) As Double
Application.Volatile True
COUNTABOLD = 0
For Each c In myRange
If c.Font.Bold = True Then COUNTABOLD = COUNTABOLD + c.Value
Next c
End Function


Is this even possible to do? If so where did I go wrong? I am returning a #VALUE! when I use the above macro.

Any help would be greatly appreciated.

Bill
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
You must change your functions name, you cannot use: COUNTABOLD!
Cleaned up your code!

This works!

Function COUNTBOLD(myRange)
Application.Volatile True

For Each c In myRange
If c.Font.Bold = True Then COUNTBOLD = COUNTBOLD + 1
Next c
End Function
 

easybpw

Active Member
Joined
Sep 30, 2003
Messages
406
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Thanks for the help. Does this work with a counta formula? That is what I want. Actually I have another version of the macro that seems to work. Which is better? This is what I have:

Function COUNTABOLD(myRange) As Double
Application.Volatile True
COUNTABOLD = 0
For Each c In myRange
If c.Font.Bold = True Then COUNTABOLD = COUNTABOLD + 1
Next c
End Function


With this all I changed was the + c.value.
I changed it to + 1

The macro seems to be returning correct results. Which version is better to use?

Bill
 

Watch MrExcel Video

Forum statistics

Threads
1,118,530
Messages
5,572,702
Members
412,481
Latest member
nhantam
Top