Macro to pull data from multiple workbooks

mathmani

New Member
Joined
May 3, 2011
Messages
4
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
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,224,606
Messages
6,179,866
Members
452,948
Latest member
UsmanAli786

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