Sub 按钮1_单击()
Dim Arr, i&, sz, gs, j&, aa
Dim d, k, t
Set d = CreateObject("Scripting.Dictionary")
Sheet1.Activate
sz = [m1].Value: gs = [u1].Value
'Arr = [a1].CurrentRegion
Arr = Sheet1.Range("a:a")‘改成这样直接获得A列或其他列数据
For i = 1 To UBound(Arr) - gs
If Arr(i, 1) = sz Then d(Arr(i, 1)) = d(Arr(i, 1)) & i & ","
Next
k = d.keys: t = d.items: n = 1
For i = 0 To UBound(k)
t(i) = Left(t(i), Len(t(i)) - 1)
If InStr(t(i), ",") Then
aa = Split(t(i), ",")
For j = 0 To UBound(aa)
Cells(n, 22).Resize(gs, 1) = Cells(aa(j) + 1, 2).Resize(gs, 1).Value
n = n + gs
Next
Else
[v1].Resize(gs, 1) = Cells(t(i) + 2, 2).Resize(gs, 1).Value
End If
Next
End Sub
一样得不到正确的数据。。。
如图。。。
正确结果应该为
1
10
8
4
又比如 提取 10的后两个数值
正确结果应该为:
2
7
1
8
代码搞不懂为什么会提取错误了
|