Count multiple worksheets qty of rows

jon110763

New Member
Joined
Oct 17, 2013
Messages
15
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
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,044
Office Version
2019
Platform
Windows
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
 

jon110763

New Member
Joined
Oct 17, 2013
Messages
15
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:

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,044
Office Version
2019
Platform
Windows
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:

jon110763

New Member
Joined
Oct 17, 2013
Messages
15
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
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,044
Office Version
2019
Platform
Windows
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:

Forum statistics

Threads
1,078,437
Messages
5,340,275
Members
399,361
Latest member
Linford

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top