+ Reply to Thread
Results 1 to 5 of 5

how to count populated rows?

  1. #1
    Ryan Cain
    Guest

    how to count populated rows?

    How do I find out how many rows have data in them starting with row 4 and
    beyond? It's ok if I just know that column A has data in it.

    I'm using VBA. I don't know how to use functions very well. But I know
    visual basic some. So if you could give me some VBA code to do this, that
    would be great. Thanks.

  2. #2
    Jim Cone
    Guest

    Re: how to count populated rows?

    Ryan,

    I was doubtful that just knowing there was data would be enough...
    So following is some code to cover several possibilities.
    (you can understand how some of this works if you look up the terms
    used in the help file - just stick the cursor in a word and press F1)
    '------------------
    Sub FindStuff()
    Dim lngRw As Long
    Dim lngCount As Long
    Dim strBlanks As String
    Dim strData As String

    'Last row with data in Column A
    lngRw = Cells(Rows.Count, 1).End(xlUp).Row

    'Count of cells with data in Column A (below cell A4)
    lngCount = WorksheetFunction.CountA(Range("A5", Cells(Rows.Count, 1)))

    'Address of cells with blanks (below cell A4)
    strBlanks = Range("A5", _
    Cells(lngRw, 1)).SpecialCells(xlCellTypeBlanks).Address

    'Address of cells with values (below cell A4)
    strData = Range("A5", _
    Cells(lngRw, 1)).SpecialCells(xlCellTypeConstants).Address

    'Address of cells with formulas (below cell A4)
    strData = strData & "," & Range("A5", _
    Cells(lngRw, 1)).SpecialCells(xlCellTypeFormulas).Address

    'Put it all together and display it
    MsgBox "Last row is " & lngRw & vbCr & "Location of blank cells is " & _
    strBlanks & vbCr & "Total cell count with data is " & _
    lngCount & vbCr & "Location of cells with data is " & strData
    End Sub
    '-------------------------------

    Regards,
    Jim Cone
    San Francisco, USA



    "Ryan Cain" <[email protected]> wrote in message
    news:[email protected]...
    How do I find out how many rows have data in them starting with row 4 and
    beyond? It's ok if I just know that column A has data in it.

    I'm using VBA. I don't know how to use functions very well. But I know
    visual basic some. So if you could give me some VBA code to do this, that
    would be great. Thanks.

  3. #3
    Registered User
    Join Date
    07-01-2004
    Location
    Kent, UK
    Posts
    74
    to do it using a worksheet function try this:

    =COUNTIF(A4:A100,">""")

  4. #4
    Tushar Mehta
    Guest

    Re: how to count populated rows?

    If your data are contiguous, COUNTA(A:A) will give you the result. If
    not, Activesheet.Cells(ActiveSheet.rows.count,1).end(xlup).row will
    give you the last row with data. Adjust the result for the offset for
    A4.

    --
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Excel, PowerPoint, and VBA add-ins, tutorials
    Custom MS Office productivity solutions

    In article <[email protected]>,
    [email protected] says...
    > How do I find out how many rows have data in them starting with row 4 and
    > beyond? It's ok if I just know that column A has data in it.
    >
    > I'm using VBA. I don't know how to use functions very well. But I know
    > visual basic some. So if you could give me some VBA code to do this, that
    > would be great. Thanks.
    >


  5. #5
    Tushar Mehta
    Guest

    Re: how to count populated rows?

    My previous post was incorrect about the limitation on when COUNTA
    would be applicable. It will work with contiguous *and* non-contiguous
    data.

    --
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Excel, PowerPoint, and VBA add-ins, tutorials
    Custom MS Office productivity solutions

    In article <[email protected]>,
    [email protected] says...
    > How do I find out how many rows have data in them starting with row 4 and
    > beyond? It's ok if I just know that column A has data in it.
    >
    > I'm using VBA. I don't know how to use functions very well. But I know
    > visual basic some. So if you could give me some VBA code to do this, that
    > would be great. Thanks.
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1