So Question again; Why does COUNTA('C:\Users\User\Documents\[filename.xlsm]'!$A:$A) work but not CountIf? (and closed .xlsm versus closed .xls/x?)

Spyros13

Board Regular
Joined
Mar 12, 2014
Messages
175
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Interesting question I encountered. Why does the following work

Code:
Sub main()

Dim FName1 As String

'   Path to Family Mapping.xlsx
    'FName1 = "C:\Users\User\Documents\[filename.xlsx]" IGNORE
    'FName1 = "C:\Users\User\Documents\[filename.xls]" IGNORE 
    FName1 = "C:\Users\User\Documents\[filename.xlsm]" 'WORKS FOR .XLSM
   
    'get row count of closed workbook [Family Mapping.xlsx] Worksheet "BMS-DES-POBA"
    Const ShName1 As String = "Sheet1"
    Const ColNo1 As Integer = 1
    Dim ShNew1 As Worksheet
    Dim LastRow5 As Long
    Dim LastRow6 As Long
    Debug.Print FName1
    Application.DisplayAlerts = False
    Set ShNew1 = Worksheets.Add
    With ShNew1.Range("A1")
        .FormulaR1C1 = "=COUNTa('" & FName1 & ShName1 & "'!C" & ColNo1 & ")"
        '.FormulaR1C1 = "=COUNTif('" & FName1 & ShName1 & "'!C" & ColNo1 & "," & Chr(34) & "*" & Chr(34) & ")" 'DITTO
        '.FormulaR1C1 = "=COUNTif('" & FName1 & ShName1 & "'!C" & ColNo1 & "," & Chr(34) & "*" & Chr(34) & ")" THIS SHOULD WORK (AND DOES IF THE FILE IS OPENED, BUT NOT WHEN CLOSED)
    
        'LastRow5 = .Value 'IGNORE
    End With
   
    'ShNew1.Delete 'IGNORE
    Application.DisplayAlerts = True
    Debug.Print Trim(LastRow5) + 1
End Sub

and even without a macro, I can read the closed files ranges and rows and get an accurate response (open .xlsm files) , with this typed out in A1:

Code:
=COUNTA('C:\Users\User\Documents\[filename.xlsm]Sheet1'!$A:$A)

but this returns error when the file is closed?

Code:
=COUNTIF('C:\Users\User\Documents\[filename.xlsm]Sheet1'!$A:$A,"*")

but yet displays correct result when opened?

Is it something to do with the way I have written
Code:
FormulaR1C1 = "=COUNTif('" & FName1 & ShName1 & "'!C" & ColNo1 & "," & Chr(34) & "*" & Chr(34) & ")"
or is it the macro (?? doubt that ) or is it some property of CountA that allowes it to work no matter if the file is closed or not, but yet same propery with countif can only let it work with open workbooks. What detfect does Countif(range,"*") have compared to counta(range).

Anyone know? Can anyone explain ?? and thus enlighten me?? Many thanks for reading and your responses if you do.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
See response #3 in the link below.

 
Upvote 0
BOWING TO YOU lieing prostrate on the floor at your feet with a clasped hand prayer symbol above on the crown of my head !!! !! Thank You!!
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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