ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   counting cell by color and condition (https://www.excelbanter.com/excel-discussion-misc-queries/139922-counting-cell-color-condition.html)

Mark

counting cell by color and condition
 
I'm trying count the number of cells in a column that have a particualr color
(36 for example) which also have the text "gp" in another column. I've seen
links at ozid, xldynamic and cpearson, but can't seem to get them to
reference to a text condition in addition to color. Any help
--
Mark

JLatham

counting cell by color and condition
 
Can you show us the code you're now using - or think you'd like to use - that
is at least picking up on the colors? That will help determine what
additions you need to make to look in the other column for the text part of
the problem.

I suspect that if you have some code that is doing something like this:
For Each someCell In Selection
(could be lots of ways to deal with the For Each, but all are probably going
to be referencing a single-cell at a time within the For loop)
If someCell.Interior.ColorIndex = X ' where X is a color code value

End If
Next

In that If statement, once you've got a color match, you may be able to add
another If statement to test for the "gp" elsewhere. Remember that VB is
case sensitive, so this type of thing would help with that:
If Ucase(Trim(someCell.Offset(0, nCol))) = "GP" Then
'both conditions match
' increment your counter
End If

Where nCol is the number of columns away from the column your test-for-color
cell is in. Example: you're testing color in column F and you want to see if
cell in column G on same row has "GP in it, then it would be .Offset(0,1)
but if you wanted to test if C has "GP" in it, then it would be .Offset(0,-3)

Hope that helps some.
"Mark" wrote:

I'm trying count the number of cells in a column that have a particualr color
(36 for example) which also have the text "gp" in another column. I've seen
links at ozid, xldynamic and cpearson, but can't seem to get them to
reference to a text condition in addition to color. Any help
--
Mark



All times are GMT +1. The time now is 01:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com