I am in need to use excel function COUNTA to pull count of non blank cells from multiple workbooks (without opening them) and print (Display) in a cell of a master workbook where I would be writing the vba macro to perform this task. I have written something like below but it doesn't seem to be working and the count is displaying as zeros. Can someone provide some light to it ? As of now I am only trying to display it.
Sub x()
Dim nCount As Long, rPaste As Range, sFolder As String, Filename As String
sFolder = "FOLDER NAME WHERE ALL THE WORKBOOKS ARE PRESENT\"
ChDir sFolder
With Application
.ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = False
End With
On Error Resume Next
Filename = Dir(sFolder & "*.xls")
Do While Filename <> ""
Workbooks.Open sFolder & Filename, Password:="PASSWORD"
nCount = Application.WorksheetFunction.CountA(Range("L2"), Range("L4:L5"), Range("L7"), Range("L9"))
MsgBox (nCount)
On Error GoTo 0
With Application
.ScreenUpdating = True: .DisplayAlerts = True: .EnableEvents = True
End With
errline:
Loop
End Sub
Sub x()
Dim nCount As Long, rPaste As Range, sFolder As String, Filename As String
sFolder = "FOLDER NAME WHERE ALL THE WORKBOOKS ARE PRESENT\"
ChDir sFolder
With Application
.ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = False
End With
On Error Resume Next
Filename = Dir(sFolder & "*.xls")
Do While Filename <> ""
Workbooks.Open sFolder & Filename, Password:="PASSWORD"
nCount = Application.WorksheetFunction.CountA(Range("L2"), Range("L4:L5"), Range("L7"), Range("L9"))
MsgBox (nCount)
On Error GoTo 0
With Application
.ScreenUpdating = True: .DisplayAlerts = True: .EnableEvents = True
End With
errline:
Loop
End Sub
Last edited: