Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Counting cells which are != empty

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Counting cells which are != empty

    I have:

    ------------------
    Sub CountHowManyRowOfData()
    MsgBox ActiveSheet.UsedRange.rows.Count
    End Sub
    ---------------------

    to count how many rows have data.

    However, I've got formatted cells (with borders, etc) which are being counted in this too.... whilst i only wish to count how many rows from say the range B6 to I2000 are being used WITH DATA IN THEM. I don't want the formatted but technically empty cells in this count. Is there a way to do this?

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Leiden, The Netherlands
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You could use the CurrentRegion property if the rows you want to count are adjacent:

    Activesheet.cells(5,5).CurrentRegion.Rows.Count

    should do the trick, supposing that the top left cell of your table is cell E5

    Marc

  3. #3
    New Member
    Join Date
    Mar 2002
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I didn't realise that if a user using my spreadsheet were to use the Autofilter it would still count all the rows; is there anyway to only let it count the stuff that's SHOWING and the rows with data?

  4. #4
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try;


    Sub FilteredRow_Count()
    Dim Area As Range
    Dim Rowcount As Double

    Rowcount = -1
    '// [A1] is the start of your Filterer row
    For Each Area In [A1].CurrentRegion.SpecialCells(xlVisible).Areas
    Rowcount = Rowcount + Area.Rows.Count
    Next

    MsgBox Rowcount

    End Sub



    Kind Regards,
    Ivan F Moala From the City of Sails

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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