我使用下面的VBA有一個共同的IDCONCATENATE僅顯示行
Function JoinAll(ByVal BaseValue, ByRef rng As Range, ByVal delim As String)
Dim a, i As Long
a = rng.Value
For i = 1 To UBound(a, 1)
If a(i, 1) = BaseValue Then JoinAll = JoinAll & _
IIf(JoinAll = "", "", delim) & a(i, 3)
Next
End Function
作爲一個例子來連接行:
ID | Date | Purchase | Concat Value
1 | 3/4/16 | Car | Car, Cap
2 | 5/2/12 | Cat | Cat
1 | 6/2/13 | Cap | Cap
運行時,這將創建汽車,帽。
然而,這是帶有過濾器的表,一旦它被過濾,以這樣的:
ID | Date | Purchase | Concat Value
1 | 3/4/16 | Car | Car, Cap
2 | 5/2/12 | Cat | Cat
它仍然顯示了汽車,蓋,而不是忽略上限是不可見的。
我看到這個答案,但沒有看到如何使它與我目前的工作VBA:
Excel VBA Concatenate only visible cells of filtered column. Test code included
UPDATE: 使用此我得到的只是可見的項目加入,但我需要它在列返回值3.這僅在第1列返回值:
Function JoinAll(ByVal BaseValue, ByRef rng As Range, ByVal delim As String)
For Each a In rng
If a = BaseValue And a.EntireRow.Hidden = False Then
JoinAll = JoinAll & IIf(JoinAll = "", "", delim) & a
End If
Next a
End Function
它並不清楚你想要連接的是什麼。這將有助於:將數據結構的轉儲與幾行僞數據(最小示例)進行轉儲。確切地確定你想要連接的內容 - 例如,你所在的行中的哪些單元格以及你期待的結果是什麼等等等等。看到一個問題已經花費了一些時間/精力來鼓勵回答,還有更多。 – 2014-08-27 21:42:06
我修改了我的問題,以獲得更多關於結構 – Kode 2014-08-27 21:58:59
的詳細信息。格式仍然很臭,但我可以用這個:-) – 2014-08-27 22:10:27