Excel - Using COUNTIF/COUNTIFS across multiple sheets/same column

后端 未结 4 1920
甜味超标
甜味超标 2020-12-03 12:28

I am trying to \"COUNT\" the number of a certain object in column I (in this instance) across multiple sheets. That value in column I is the result of a formula (if it matte

4条回答
  •  醉话见心
    2020-12-03 13:28

    My first post... UDF I managed quickly to compile. Usage: Select 3D range as normal and enclose is into quotation marks like below...

    =CountIf3D("'StartSheet:EndSheet'!G16:G878";"Criteria")

    Advisably sheets to be adjacent to avoid unanticipated results.

    Public Function CountIf3D(SheetstoCount As String, CriteriaToUse As Variant)
    
         Dim sStarSheet As String, sEndSheet As String, sAddress As String
         Dim lColonPos As Long, lExclaPos As Long, cnt As Long
    
        lColonPos = InStr(SheetstoCount, ":") 'Finding ':' separating sheets
        lExclaPos = InStr(SheetstoCount, "!") 'Finding '!' separating address from the sheets
    
        sStarSheet = Mid(SheetstoCount, 2, lColonPos - 2) 'Getting first sheet's name
        sEndSheet = Mid(SheetstoCount, lColonPos + 1, lExclaPos - lColonPos - 2) 'Getting last sheet's name
    
        sAddress = Mid(SheetstoCount, lExclaPos + 1, Len(SheetstoCount) - lExclaPos) 'Getting address
    
            cnt = 0
       For i = Sheets(sStarSheet).Index To Sheets(sEndSheet).Index
            cnt = cnt + Application.CountIf(Sheets(i).Range(sAddress), CriteriaToUse)
       Next
    
       CountIf3D = cnt
    
    End Function
    

提交回复
热议问题