這應該工作。
它不,但它應該。雖然可以幫助別人。
Sub ert()
e = NamesArrayFiltered(Range("B:B"), Range("D:D"), 1, Range("A:A"), "2014.AOK")
MsgBox e
End Sub
'
Public Function NamesArrayFiltered(myNames As Range, Optional Filter1 As Range, Optional FilterCriterion1 As Variant, _
Optional Filter2 As Range, Optional FilterCriterion2 As Variant) As String
NamesArrayFiltered = ""
Dim FilterFound(1 To 2) As Boolean
FilterFound(1) = Not Filter1 Is Nothing
If FilterFound(1) Then FilterFound(1) = Not Filter1 Is Nothing
FilterFound(2) = Not Filter2 Is Nothing
If FilterFound(2) Then FilterFound(2) = Not Filter2 Is Nothing
Set Filter1 = Intersect(Filter1, Filter1.Worksheet.UsedRange)
Set myNames = Intersect(myNames, myNames.Worksheet.UsedRange)
Set Filter2 = Intersect(Filter1, Filter1.Worksheet.UsedRange)
Dim RowsCount As Long, ColumnsCount As Long, CellsCount As Long
RowsCount = Filter1.Rows.Count
ColumnsCount = Filter1.Columns.Count
CellsCount = Filter1.Cells.Count
Dim NamesArray() As Variant, Counter1 As Long
ReDim NamesArray(1 To CellsCount)
Counter1 = 1
On Error Resume Next
For i = 1 To RowsCount
For j = 1 To ColumnsCount
If FilterFound(1) Then
If Filter1(i, j).Value2 = FilterCriterion1 Then
If FilterFound(2) Then
If Filter2(i, j).Value2 = FilterCriterion2 Then
NamesArray(Counter1) = myNames(i, j).Value2
Counter1 = Counter1 + 1
End If
Else
NamesArray(Counter1) = myNames(i, j).Value2
Counter1 = Counter1 + 1
End If
End If
End If
'If (Filter1(i, j).Value2 = FilterCriterion1 And FilterFound(1)) And (Filter1(i, j).Value2 = FilterCriterion1 And FilterFound(1)) Then
' NamesArray(Counter1) = myNames(i, j).Value2
' Counter1 = Counter1 + 1
'End If
Next j
Next i
NamesArrayFiltered = Join(NamesArray(), ", ")
NamesArrayFiltered = Left(NamesArrayFiltered, InStr(NamesArrayFiltered, ", , ") - 1)
End Function
如何使用數據透視表? – Raystafarian
我不知道它是否可以工作。我通過打開一個XML文件來獲得這種數據。這一行動是我正在開發的一個宏觀宏觀的一部分。 但我會考慮你的想法。感謝隊友:) – Eka
'ORIGIN'和'DISTRIBUTED'是否互斥? ORIGIN是每個'REFERENCE'的單個值嗎? – user3819867