×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

OPTION IN 'COUNTIF' COMMAND

OPTION IN 'COUNTIF' COMMAND

OPTION IN 'COUNTIF' COMMAND

(OP)
I am not familier with writing of Macros in EXCEL.

I have an Excel spreadsheet in which I have data of different categories identified through different colour fills in the respective cells.

If I have to count the number of cells with a specific category, is there any option in countif command to count the cells with same colour fill?

Thanks for the help.

RE: OPTION IN 'COUNTIF' COMMAND

Unfortunately, you cannot retrieve the colorindex of a cell with a standard function in Excel, so you have to write your own user defined function. Go to the VB editor (Alt-F11 or Tools/Macro/Visual Basic editor), then insert a module, and write the following code:

CODE

Function GetColorIndex(R As Range) As Long
    Application.Volatile
    GetColorIndex = R(1, 1).Interior.ColorIndex
End Function
Go back to your spreadsheet, and you have available a user defined function to get the color of a cell by its index. You can call it as: =GetColorIndex(A1), which will return a number corresponding to the color of cell [A1]. Modify as needed!

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.

RE: OPTION IN 'COUNTIF' COMMAND

You could add a column for a category code, use menu/format/conditional format to color code based on the category code, and COUNTIF the category codes.

------------------------------------------
     "...students of traffic are beginning to realize the false economy of mechanically controlled traffic, and hand work by trained officers will again prevail."

              Wm. Phelps Eno, ca. 1928

RE: OPTION IN 'COUNTIF' COMMAND


Kudos to ACtrafficengr !

A very elegant and appropriate solution, indeed. Thanks.

RE: OPTION IN 'COUNTIF' COMMAND

(OP)
Thanks Joerd and ACtrafficengr.

The tips were really helpful

Trilinga

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources