Count multiple worksheets qty of rows

jon110763

New Member
Joined
Oct 17, 2013
Messages
16
Hi,
I have a number of workbooks, named by date they were created, and need a summary of how many rows each workbook has.

Thanks

Jon
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Code:
Option Explicit


Sub CountRows()
    Dim ws As Worksheet
    Dim lr As Long
    For Each ws In Worksheets
        lr = ws.Range("A" & Rows.Count).End(xlUp).Row
        MsgBox (ws.Name & " has " & lr & "rows")
    Next ws
End Sub
 
Upvote 0
Hi Alan,
thank you for the quick response. I think i should explain a bit better.
The title post should've read workbooks.
I create a workbook for each day with varying amount of rows, and I should've counted and recorded each day in a separate summary. I need now to go back to the beginning of the year to have a count for each day.
hope that is clearer

jon
 
Last edited:
Upvote 0
are there more than one sheet in each workbook? Are all workbooks in the same directory? What is the full path name for the workbooks directory? How do you want the results published? Where?
 
Last edited:
Upvote 0
are there more than one sheet in each workbook? Are all workbooks in the same directory? What is the full path name for the workbooks directory? How do you want the results published? Where?

Hi Alan

1 sheet in each workbook
all in the same folder called "Daily Reports" saved on my desktop

results as one new worksheet "Quantities" with columns Date and Qty, saved in the same folder "Daily reports' on my desktop

thank you

jon
 
Upvote 0
See if this air code works for you.

Code:
Sub CountRows()


    Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim ws As Worksheet
    Dim sPath As String
    Dim lr As Long, lrW As Long
    Dim ws As Workbook
    Set wb = ThisWorkbook.Sheets("Sheet1")


    Set objFSO = CreateObject("Scripting.FileSystemObject")


    'Get the folder object associated with the directory
    sPath = InputBox("What is the full Path to Search?")
    Set objFolder = objFSO.GetFolder(sPath)




    'Loop through the Files collection
    For Each objFile In objFolder.Files
        lr = ws.Range("A" & Rows.Count).End(xlUp).Row
        lrW = wb.Range("A" & Rows.Count).End(xlUp).Row + 1
        wb.Range("A" & lrW) = ws.Name
        wb.Range("B" & lrW) = lr
    Next


    Set objFolder = Nothing
    Set objFile = Nothing
    Set objFSO = Nothing


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,915
Members
448,532
Latest member
9Kimo3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top