open files, count rows, record findings

keith05281967

Board Regular
Joined
May 6, 2011
Messages
68
Greetings,

Okay, i'm a bit more prepared to ask my question this time.
I'd like to be able to go thru all the workbooks in a folder, check the row count and record that information either in a msgbox or spdsheet. I have some code that does some of this. I probably need to add an array to record all the counts


Sub RowCount()
Dim path As Variant
Dim excelfile As Variant
Dim NumRows As Integer

path = "C:\Documents and Settings\My Documents\Macro Testing\test directory code\"

excelfile = Dir("*.xls")
Do While excelfile <> ""
Workbooks.Open Filename:=path & excelfile
excelfile = Dir
NumRows = Application.WorksheetFunction.CountA(Range("A1:A65536"))
ActiveWorkbook.Close

Loop

End Sub


I'd want the results to look like this:

fileA........................50
fileB........................35
filec........................112


thanks,
Keith
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi, :)

try it this way ...

Code:
Option Explicit
Const strFolder As String = "C:\Temp\"
Sub Main()
    Dim objWorkbook As Workbook
    Dim strFilename As String
    Dim dblCount As Double
    Dim intCalc As Integer
    Dim lngRow As Long
    On Error GoTo Fin
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
            intCalc = .Calculation
            .Calculation = xlCalculationManual
            .ShowWindowsInTaskbar = False
        End With
        strFilename = Dir$(strFolder & "*.xls")
        Do Until strFilename = vbNullString
            Set objWorkbook = Workbooks.Open(Filename:= _
                strFolder & strFilename, UpdateLinks:=0, ReadOnly:=True)
            lngRow = lngRow + 1
            dblCount = Application.WorksheetFunction.CountA(Range("A:A"))
            objWorkbook.Close False
            Sheet1.Cells(lngRow, 1).Value = strFilename
            Sheet1.Cells(lngRow, 2).Value = dblCount
            strFilename = Dir$()
            Set objWorkbook = Nothing
        Loop
Fin:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = intCalc
        .ShowWindowsInTaskbar = True
    End With
    If Err.Number <> 0 Then MsgBox "Error: " & _
        Err.Number & " " & Err.Description
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,147
Members
452,891
Latest member
JUSTOUTOFMYREACH

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