“Unable to get the Countif property of the Worksheetfunction class” error

后端 未结 2 902
萌比男神i
萌比男神i 2021-01-21 14:07

I get a \"Unable to get the Countif property of the Worksheetfunction class\" error when using this code

    Windows(\"usertemp.xls\").Activate
Selection.AutoFil         


        
2条回答
  •  失恋的感觉
    2021-01-21 14:10

    The SpecialCells(xlCellTypeVisible) will create a disjointed range and Countif does not play nice with disjointed ranges.

    You will need to use a loop to loop through each criteria and add the Countifs together.

    Try this:

    Dim arr() as variant
    Dim arrPart as variant
    arr = Array("28", "BE", "CH", "DE", "FR", "JP", "NL")
    
    Dim Impats As Integer
    
    For Each arrPart in arr
        Impats = Impats + Application.WorksheetFunction.CountIfs(ActiveSheet.Range("AL:AL"), "I",ActiveSheet.Range("N:N"),arrPart)
    Next arrPart
    MsgBox Impats
    

提交回复
热议问题