|
方法如版主的回复,中间加入了清除K2:T2的值,否则会保留上一次的结果。
加入单元格的值转换为字符串,统一模式。
- Private Sub CommandButton1_Click()
- Dim hm1%, hm2%, hm3%
- Dim i%, j%, cellValue$
- Dim dict
- Dim k, v
-
- hm1 = Sheet1.Cells(1, 4)
- hm2 = Sheet1.Cells(1, 5)
- hm3 = Sheet1.Cells(1, 6)
- Set dict = CreateObject("Scripting.Dictionary")
- For i = 4 To 10
- For j = 3 To Sheet1.[b65535].End(xlUp).Row - 3
- If Sheet1.Cells(j, i) = hm1 And Sheet1.Cells(j + 1, i) = hm2 And Sheet1.Cells(j + 2, i) = hm3 Then
- cellValue = Sheet1.Cells(j + 3, i)
- dict(cellValue) = dict(cellValue) + 1
- End If
- Next j
- Next i
-
- k = dict.keys
- t = dict.items
- Sheet1.Range("K2:T2").ClearContents
- For i = 0 To UBound(k)
- Debug.Print (k(i) & "==" & t(i))
- Sheet1.Cells(2, k(i) + 11) = t(i)
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|