Question

I have searched everywhere for this one but can't find a solution. Please help! I have used this site a lot and know there are a lot of clever people out there!

I would like to divide the number of times a unique value appears in a column by the number of times a selected multiple values appear in a column.

For example, I would like to know the percentage of times the value 2 appears out of the number of times values 1,2,3,4,5 appear (but not 6 in this list):

1
2
2
2
3
5
6
6

2 appears three times, but I want this as a percentage of 6 not 8, the correct answer being 50% not 37.5%.

I have tried =(COUNTIF(Jan!C7,2))/(COUNT(Jan!C7,"<6")) which seems to work when entered directly into the spreadsheet (with the correct column labels) but not when entered in VBA as ActiveCell.FormulaR1C1 = "=(COUNTIF(Jan!C7,1))/(COUNT(Jan!C7,"<6"))" - it throws back an error.

Many thanks in advance if anyone can help.

Was it helpful?

Solution

If C7:C14 are

1
2
2
2
3
5
6
6

then =(COUNTIF(C7:C14,"=2"))/(COUNTIF(C7:C14,"<6")) will display .5 which is 50%

enter image description here

further,

to use this in VBA you need

ActiveCell.Formula = "=(COUNTIF(C7:C14,""=2""))/(COUNTIF(C7:C14,""<6""))"

Note: you need to wrap " with another " to escape the double quote inside a string

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top