I want to count the number of cells with data in a column.
I have to count these cells from all the workbooks.
For example, I have 2 workbooks: WB1 and WB2.
- Worksheet WS1 with data in A1, A2, A3, A4
- Worksheet WS2 with data in A1, A2.
- My output should show 6.
How can I count this?
Option Explicit
Private Sub CommandButton1_Click()
Dim paths(), wbs() As Workbook
Dim x As Integer
Dim sh, rn, k
paths = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", _
MultiSelect:=True, Title:="Please browse all the Rawdata files")
For x = 1 To UBound(paths)
ReDim wbs(UBound(paths))
Set wbs(x) = Workbooks.Open(paths(x))
Set sh = wbs(x).Sheets("Role ID - Description")
Set rn = sh.UsedRange
k = rn.Rows.Count + rn.Row - 1 - 1
wbs(x).Close
Next
End Sub