Counting Cells

P

Pedro Marques

Hi
What code should I write in order to count only the positive value of a
pre-defined range: Range(Cells(42, 2), Cells(77, 2))

Thanks
Pedro
 
N

Nick

Total = 0

For J = 42 to 77

If Cells(J, 2).Value > 0 Then

Total = Total + Cells(J, 2).Value

Next J
 
N

Nick

Thinking about it if you only want to count the number of
cells rather than sum them you should use

application.worksheetfunction.countif
 
P

Pedro Marques

Thanks Nick

I tried to use the application.worksheetfunction.countif

Using strRet = Application.WorksheetFunction.CountIf((Range(Cells(42, 2),
Cells(77, 2))), Cells.Value > 0)

But it gives me an error.

Do you know what do I have to change?
 
M

Mike

One command, no looping required.

Application.WorksheetFunction.CountIf(Range(Cells(42, 2),
Cells(77, 2)),">0")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top