PDA

View Full Version : Count populated cells



alwayslearn
09-06-2008, 01:42 PM
I am having trouble with some code. I need to count the number of populated cells in a given range and output the count to another cell. Can anyone help me out.

Thanks.

mdmackillop
09-06-2008, 02:29 PM
=COUNTA(A1:Z50)

for code

Range("AA1") = Application.Counta(Range("A1:Z50"))

alwayslearn
09-06-2008, 03:00 PM
I was using this:


ActiveCell.FormulaR1C1 = "=COUNTA(R[4]C[-2]:R[4994]C[-2])"
Range("O8").Select


The problem is it is taking the range from M12:M5002 and I need it from B9:B5000--where is that coming from in the code?

mdmackillop
09-06-2008, 03:35 PM
R[4]C[-2] uses relative references

try

ActiveCell.FormulaR1C1 = "=COUNTA(R9C2:R5000C2)"

alwayslearn
09-06-2008, 04:49 PM
The code I have is activated upon a button click event. When I click it once I get the value in a random cell. Then I have to click in again to populate O9. Not sure why this is happening.

mdmackillop
09-06-2008, 05:34 PM
If you have specific requirements, why not spell them out in your first post?

alwayslearn
09-06-2008, 06:17 PM
Sorry the more I am working on it the more I am figuring out that my solution is not going to work. I am going to set up my spreadsheet better and post the full file shortly on a new thread--thanks for all the help.