nguyenanhdung8111982
Thành viên hoạt động
- Tham gia
- 1/11/19
- Bài viết
- 120
- Được thích
- 33
- Giới tính
- Nam
Tôi có thấy đoạn code đếm hàng loạt file excel có bao nhiêu hàng. Giờ tôi muốn đếm hàng loạt file excel
theo cột chỉ định ví dụ đếm cột C từ C2 trở đi hoặc Cột F từ F2 trở đi và chỉ đếm những ô nào có dữ liệu, giống hàm CountA trong excel. Cám ơn cả nhà!!
File excel test đính kèm.
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
theo cột chỉ định ví dụ đếm cột C từ C2 trở đi hoặc Cột F từ F2 trở đi và chỉ đếm những ô nào có dữ liệu, giống hàm CountA trong excel. Cám ơn cả nhà!!
File excel test đính kèm.
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
File đính kèm
Lần chỉnh sửa cuối: