Consulting

Results 1 to 7 of 7

Thread: Count populated cells

  1. #1

    Count populated cells

    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.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    =COUNTA(A1:Z50)

    for code
    [VBA]
    Range("AA1") = Application.Counta(Range("A1:Z50"))
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    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?

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    R[4]C[-2] uses relative references

    try
    [VBA]
    ActiveCell.FormulaR1C1 = "=COUNTA(R9C2:R5000C2)"
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    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.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you have specific requirements, why not spell them out in your first post?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •