Count Rows in worksheets


Public Sub Count_Rows_in_Sheets()

' Simple count of rows in data sheets starting at worksheet 2 where all worksheets data starts
' in row 6.  The results are placed in worksheet 1 in
' column 7 (Worksheet Name )and 8 ( number of rows counted with data in Column 1 )
' Data output starts in row 3

Dim ws1 As Worksheet
Dim ws As Worksheet
Dim c As Integer
Dim r As Integer
Dim i As Integer
Dim cn As Integer

Set ws1 = ThisWorkbook.Sheets(1) ' sets worksheet 1 as output sheet
r = 3  ' Sets output data row

For i = 2 To (ThisWorkbook.Sheets.Count) ' For all worksheets in Workbook
    Set ws = ThisWorkbook.Sheets(i)
    c = 0
    cn = 6
'   Count the number of rows with data in them
    While Trim(ws.Cells(cn, 1)) <> ""
        c = c + 1
        cn = cn + 1
    Wend
    ws1.Cells(r, 8) = c
    ws1.Cells(r, 7) = ws.Name
    r = r + 1
    Set ws = Nothing
Next i

End Sub