smarty1995
New Member
- Joined
- Jan 18, 2020
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Hi If any one can help me with below macro
This only counts first sheet of each file however I need count for all sheets in a workbook.
Sub CollectData()
Dim fso As Object, xlFile As Object
Dim sFolder$
Dim r&, j&
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.InitialFileName = ThisWorkbook.Path
If .Show Then sFolder = .SelectedItems(1) Else Exit Sub
End With
Set fso = CreateObject("Scripting.FileSystemObject")
For Each xlFile In fso.GetFolder(sFolder).Files
With Workbooks.Open(xlFile.Path)
With .Sheets(1)
j = .Cells(.Rows.Count, 1).End(xlUp).Row
End With
.Close False
End With
r = r + 1
Cells(r, 1).Value = xlFile.Name
Cells(r, 2).Value = j
Next
End Sub
This only counts first sheet of each file however I need count for all sheets in a workbook.
Sub CollectData()
Dim fso As Object, xlFile As Object
Dim sFolder$
Dim r&, j&
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.InitialFileName = ThisWorkbook.Path
If .Show Then sFolder = .SelectedItems(1) Else Exit Sub
End With
Set fso = CreateObject("Scripting.FileSystemObject")
For Each xlFile In fso.GetFolder(sFolder).Files
With Workbooks.Open(xlFile.Path)
With .Sheets(1)
j = .Cells(.Rows.Count, 1).End(xlUp).Row
End With
.Close False
End With
r = r + 1
Cells(r, 1).Value = xlFile.Name
Cells(r, 2).Value = j
Next
End Sub