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,071
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,071
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,071
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,081,832
Messages
5,361,586
Members
400,639
Latest member
fleyd

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top