2017-08-03 61 views
0

我需要,如果「T =」值在列A包含一個Semikolon到數列A計數Filterd範圍與乘法條件

enter image description here

所有地址的部分結果它長谷雙數,如果它包含2個Semikolons則計數爲3,等等......

她是一張圖片,顯示計數應如何工作。

我有公式計算狀態完成或待定的數量以及計算總金額的公式。

此圖片所示。 enter image description here

由於沒有過濾器,您可以看到部分結果與總金額一樣爲22。

當我設置一個過濾器時,它應該只顯示可見單元的數量,在這張圖片中。

enter image description here

回答

1

UPDATE:
周圍的一些生根多後,我發現了一個竅門應該這樣做。它需要作爲數組函數輸入(Ctrl + Shift + Enter)。

=SUMPRODUCT((LEN(Range)-LEN(SUBSTITUTE(Range,";","")) +1)*--(SUBTOTAL(103,OFFSET(FirstCell,ROW(Range)-ROW(FirstCell),0))=1))

在你的情況,FirstCell是A7和範圍是A7:A22。

小計(103,...)是一個CountA函數,但它忽略隱藏的單元格。但是,它只返回一個值(隱藏單元的數量),除非它給出了一個引用數組,這是Offset無意義提供的。
注:這個問題是非常相似this one.


讓我知道如果這樣做的伎倆:

Function CountFilter(rng As Range, delimiter As String) As Integer 
    CountFilter = 0 
    For Each c In rng 
     If Rows(c.Row).Hidden = False Then 
      CountFilter = CountFilter + 1 + CountChrInString(c.Value, delimiter) 
     End If 
    Next c 
End Function 

Public Function CountChrInString(Expression As String, Character As String) As Long 
'' 
''' Returns the count of the specified character in the specified string. 
''' 
' 
' ? CountChrInString("a/b/c", "/") 
' 2 
' ? CountChrInString("a/b/c", "\") 
' 0 
' ? CountChrInString("//////", "/") 
' 6 
' ? CountChrInString(" a/b/c ", "/") 
' 2 
' ? CountChrInString("a/b/c", "/") 
' 0 
' 
    Dim iResult As Long 
    Dim sParts() As String 

    sParts = Split(Expression, Character) 

    iResult = UBound(sParts, 1) 

    If (iResult = -1) Then 
    iResult = 0 
    End If 

    CountChrInString = iResult 

End Function 

CountChrInString功能從here恬不知恥地複製。

+0

剛纔意識到你並沒有在尋找VBA。沒關係。 – TBlock

+0

謝謝,作品完美 – Moosli