User defined function help

easybpw

Active Member
Joined
Sep 30, 2003
Messages
411
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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

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
411
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,809
Messages
5,833,790
Members
430,233
Latest member
cbutts

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top