Sub 字典记录行号_条件去重统计()
Dim Arr, 结果数组(), i As Long, k As Long, 关键字 As String, dic As Object
tim = Timer
Arr = Sheet1.[a1].CurrentRegion '原始数据装入数组
Set 结果起始单元格 = Sheet1.[i2]
ReDim 结果数组(1 To UBound(Arr, 1), 1 To UBound(Arr, 2))
Set dic = CreateObject("scripting.dictionary")
Set dic房间编号 = CreateObject("scripting.dictionary")
For i = 2 To UBound(Arr, 1) '标题行开始
关键字 = Arr(i, 1) & "|" & Arr(i, 2) & "|" & Arr(i, 3)
If Arr(i, 5) = "开放" Then
If Not dic.Exists(关键字) Then
dic房间编号(关键字) = Arr(i, 4)
k = k + 1
dic(关键字) = k '记录关键字所在结果数组中的行号位置
For j = 1 To UBound(Arr, 2) - 2 '循环多字段取值
结果数组(k, j) = Arr(i, j)
Next
结果数组(k, UBound(Arr, 2) - 1) = 1
Else
If Not "," & dic房间编号(关键字) & "," Like "*," & Arr(i, 4) & ",*" Then
dic房间编号(关键字) = dic房间编号(关键字) & "," & Arr(i, 4)
结果数组(dic(关键字), UBound(Arr, 2) - 1) = 结果数组(dic(关键字), UBound(Arr, 2) - 1) + 1 '循环多字段取值累加
End If
End If
End If
Next
结果起始单元格.CurrentRegion.ClearContents
结果起始单元格.Resize(k, UBound(Arr, 2) - 1) = 结果数组
MsgBox "执行完毕!_用时: " & Format(Timer - tim, "0.00") & " 秒"
End Sub
|