Is it possible to do a countif in VBA using a closed workbook?

Sinon

Active Member
Joined
Aug 6, 2015
Messages
298
Hi all. My current dilemma is this: I am writing a macro that will do a few things but I am stuck at having to do a countif using a range from a different workbook. Now this workbook is a binary one (xlsb not xlsx) and is password protected. It has multiple sheets as well.

What I want to do is a countif using a value from my workbook (the one with the code in it) as the criteria and using a column from a sheet from the closed xlsb workbook for my range:

COUNTIF(Range,Value)
Range = column D from a sheet in the closed workbook that is password protected
Value= cell from current open workbook

I am using WorksheetFunction.CountIf. I only need the range, which i tried setting up but I am getting runtime error 9 "Subscript out of range". I used a range variable MyRange and tried referencing the workbook with

Set MyRange=Workbooks("drive:\Folder1\Folder2\WorkbookName.xlsb").Worksheets("Sheet4").Range("D:D")

So, is it possible to do a countif using this closed, password protected workbook? And if so, how do I reference the workbook?

Thank you all
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
SUMPRODUCT works for closed workbooks.

That being said, if it's password protected you will most likely need to open and unprotect the workbook before you can do any formulas out of it.
 
Upvote 0
SUMPRODUCT works for closed workbooks.

That being said, if it's password protected you will most likely need to open and unprotect the workbook before you can do any formulas out of it.

Hi and thanks for your reply. The workbook is not protected but there is a password to open it. The password was added through the Save As window by going to Tools->General Option -> Password to open. Does your answer still apply in this case?
 
Upvote 0

Forum statistics

Threads
1,217,346
Messages
6,136,044
Members
449,981
Latest member
kjd513

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