PDA

View Full Version : [SOLVED:] CountIf with variable Range



fadib
05-29-2011, 03:41 AM
Hi guys,
I am trying to write a code that can count the number of letter "u" between two cells.
a = 32
b = 40
C = 35

Cells(C, "Z") = "=COUNTIF(Range(Cells(35,a),Cells(35,b)),""u"")"

Not working !! what I am doing wrong?

Bob Phillips
05-29-2011, 04:04 AM
Is this what you mean


Cells(C, "Z") = Application.CountIf(Range(Cells(a, "A"), Cells(b, "A")), "u")

fadib
05-29-2011, 04:18 AM
Thanks Xld,
so the trick was to use application.
Just curious, why recording a macro doesn't use "Application."?

Bob Phillips
05-29-2011, 08:24 AM
Because recording puts the formula into the formula property, you were trying to stuff it into value, but even then not using the correct values.