User defined function help

easybpw

Active Member
Joined
Sep 30, 2003
Messages
437
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 came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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
Back
Top