Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Excel 2003
I have a row of data in Excel that is in Row 4 from Column B to Column AF. In this row, some cells contain the value "X", some contain the value "O", and yet other cells in this row will contain other text data. I tried the COUNTA function but that counts every cell that has a non-null value. I need more spoecific information than that. I also tried it with an immediate if, but somehow got the syntax incorrect. Per my example above, is there a way in VBA to count across row 4 (from cell B4 to cell AF4 how many cells contain the value of "X" and place that in cell A5 and count how many cells contain the value of "O" and place that value in cell A6? Thanks. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You don't need VBA for this; just use the COUNTIF function.
A5: =COUNTIF(B4:AF4,"X") A6: =COUNTIF(B4:AF4,"O") Just put the text you want to find into the last argument. -- Rick (MVP - Excel) "RLN" wrote in message ... Excel 2003 I have a row of data in Excel that is in Row 4 from Column B to Column AF. In this row, some cells contain the value "X", some contain the value "O", and yet other cells in this row will contain other text data. I tried the COUNTA function but that counts every cell that has a non-null value. I need more spoecific information than that. I also tried it with an immediate if, but somehow got the syntax incorrect. Per my example above, is there a way in VBA to count across row 4 (from cell B4 to cell AF4 how many cells contain the value of "X" and place that in cell A5 and count how many cells contain the value of "O" and place that value in cell A6? Thanks. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Rick:
=COUNTIF(B4:AF4,"X") << This worked nicely, thank you. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try using COUNTIF
=COUNTIF(A4:AF4,"X") -- HTH, Barb Reinhardt "RLN" wrote: Excel 2003 I have a row of data in Excel that is in Row 4 from Column B to Column AF. In this row, some cells contain the value "X", some contain the value "O", and yet other cells in this row will contain other text data. I tried the COUNTA function but that counts every cell that has a non-null value. I need more spoecific information than that. I also tried it with an immediate if, but somehow got the syntax incorrect. Per my example above, is there a way in VBA to count across row 4 (from cell B4 to cell AF4 how many cells contain the value of "X" and place that in cell A5 and count how many cells contain the value of "O" and place that value in cell A6? Thanks. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub countX()
Set r = Range("B4:AF4") Set a6 = Range("A6") Set a5 = Range("A5") x = "X" o = "O" a5.Value = Application.WorksheetFunction.CountIf(r, x) a6.Value = Application.WorksheetFunction.CountIf(r, o) End Sub -- Gary''s Student - gsnu200802 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
count specific subtotal values only | Excel Discussion (Misc queries) | |||
Count zero values before specific date | Excel Worksheet Functions | |||
Count the number of specific values in a cell | Excel Worksheet Functions | |||
Trying to count specific values | Excel Worksheet Functions | |||
How do I count my data that are between specific values? | Excel Worksheet Functions |