The Straight Dope

Go Back   Straight Dope Message Board > Main > General Questions

Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2010, 10:45 AM
Parthol Parthol is offline
Guest
 
Join Date: Jul 2002
Excel question for the experts

Hi there!

Does anyone here know if it's possible to do the following in Excel?

I have a column (or row) of numbers, some of which are formatted in bold.

I want to count the number of cells in that row (or column) that are so formatted. (As opposed to the sum of those numbers).

In other words, I want a formula that returns: "how many cells within this range are formatted in bold?"

Thanks,

-P
Reply With Quote
Advertisements  
  #2  
Old 01-05-2010, 10:55 AM
Giles Giles is online now
Charter Member
 
Join Date: Apr 2004
Location: Newcastle NSW
Posts: 11,562
I think it depends on what version of Excel you are using. On the computer that I'm on at present is Excel 2003, and I think you can't do that sort of thing. However, I believe that you might be able to do in in Excel 2007: I've been told that you can do tests of cell format with that version.
Reply With Quote
  #3  
Old 01-05-2010, 11:04 AM
Parthol Parthol is offline
Guest
 
Join Date: Jul 2002
I'm using the 2007 version.
Reply With Quote
  #4  
Old 01-05-2010, 11:14 AM
Ruminator Ruminator is offline
Guest
 
Join Date: Dec 2007
Quote:
Originally Posted by Parthol View Post
In other words, I want a formula that returns: "how many cells within this range are formatted in bold?"
I believe you have to use VBA code (Visual Basic Applications) to test whether the cell's properties are bold. You use VBA to write a UDF (User Defined Function) that specifically tests for bold. I'm sure this type of function has be re-invented a 1000 times by different people so a google search should find some example code to paste into your worksheet.

Giles might be thinking of a function in Excell called CELL() but that only returns the formatting string such as "$0.00" or if the cell is protected/unprotected -- the CELL() doesn't provide color, bold, etc.


(Tangent thought... I've always wondered why people ask Excel questions here instead of dedicated forums such as http://www.excelforum.com where there are more experts and better answers.)
Reply With Quote
  #5  
Old 01-05-2010, 11:23 AM
CookingWithGas CookingWithGas is offline
Charter Member
 
Join Date: Mar 1999
Location: Tysons Corner VA
Posts: 8,995
I was unable to find this feature in Excel 2007. Doesn't mean it isn't there.

This function works in Excel 2007.

Code:
Function CountBold(r As Range) As Long
   CountBold = 0
   
   Dim c As Range
   For Each c In r
      If c.Font.Bold Then
         CountBold = CountBold + 1
      End If
   Next c
End Function
However, a change to formatting is not considered a change to the cell so will not trigger an automatic recalculation of this function. You could declare it as Volatile, but even that won't guarantee it will be recalculated when formatting changes.

Quote:
Originally Posted by Ruminator View Post
(Tangent thought... I've always wondered why people ask Excel questions here instead of dedicated forums such as http://www.excelforum.com where there are more experts and better answers.)
Bite your tongue


Actually, people come here because it's handy and quick. That's the tradeoff of a general-purpose board. Big audience who know a little about everything. Specialized boards know everything about a little. I happen to like www.ozgrid.com for Excel help, and I guess there are others that are very good too.
Reply With Quote
  #6  
Old 01-05-2010, 02:18 PM
tomndebb tomndebb is offline
Mod Rocker
Moderator
 
Join Date: Mar 1999
Location: N E Ohio
Posts: 34,379
Also, many of us talk something closer to English than the denizens of tech centered boards. If you are newly fighting your way into a situation, it helps if your guide speaks a language you understand. There are multi-lengual tech geeks and some of us only speak tech, but the odds of getting an answer in English, here, are mildly higher.
Reply With Quote
  #7  
Old 01-05-2010, 02:58 PM
CookingWithGas CookingWithGas is offline
Charter Member
 
Join Date: Mar 1999
Location: Tysons Corner VA
Posts: 8,995
Quote:
Originally Posted by tomndebb View Post
Also, many of us talk something closer to English than the denizens of tech centered boards. If you are newly fighting your way into a situation, it helps if your guide speaks a language you understand. There are multi-lengual tech geeks and some of us only speak tech, but the odds of getting an answer in English, here, are mildly higher.
That is true, but there is a reason for that. I have found that over half of the Excel questions I try to answer are so poorly worded that I have to ask a lot of questions to find out what the person is trying to do, and what problem they are having. Sometimes just reading the question shows that it isn't worth it to try to answer it.

Note that Parthol did an excellent job in formulating a precise, brief, clear question!
Reply With Quote
  #8  
Old 01-06-2010, 10:29 AM
Parthol Parthol is offline
Guest
 
Join Date: Jul 2002
Just wanted to pop back in to say 'thanks' for the responses!

Also, yeah, I asked the Dope because it's quick, familiar, and the answers are typically just as good as those from tech forums.

-P
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:43 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Send questions for Cecil Adams to: cecil@chicagoreader.com

Send comments about this website to: webmaster@straightdope.com

Terms of Use / Privacy Policy

Advertise on the Straight Dope!
(Your direct line to thousands of the smartest, hippest people on the planet, plus a few total dipsticks.)

Publishers - interested in subscribing to the Straight Dope?
Write to: sdsubscriptions@chicagoreader.com.

Copyright © 2013 Sun-Times Media, LLC.