Can I enter a formula to count values in VBA

Dobbo

New Member
Joined
Apr 2, 2002
Messages
12
The code below runs a function to get data from closed workbooks. Where it specifies range "AD:AD" can i put a formula in to count if range AD contains certain values??




cValue = GetInfoFromClosedFile(FolderName, wbList(i), wsName, ("AD:AD"))


Cells(r, 2).Formula = cValue

Private Function GetInfoFromClosedFile(ByVal wbPath As String, wbname As String, wsName As String, cellRef As String) As Variant
Dim arg As String

GetInfoFromClosedFile = ""
If Right(wbPath, 1) <> "" Then wbPath = wbPath & ""
If Dir(wbPath & "" & wbname) = "" Then Exit Function
arg = "'" & wbPath & "[" & wbname & "]" & wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)



On Error Resume Next
GetInfoFromClosedFile = ExecuteExcel4Macro(arg)
End Function
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi
I don't know if you can or not. Try it. Search help for "Using Excel Functions in Your Code"
If not, you can always loop down the column and check the cells individualy..
Tom
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,913
Members
448,532
Latest member
9Kimo3

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