|
楼主 |
发表于 2024-11-11 22:52
|
显示全部楼层
本帖最后由 快人一步 于 2024-11-12 15:38 编辑
Sub 填i列()
Dim i&, j&, k&, iRow&
Dim Arr, Brr, Hrr, Mn&, Mx&, Dkey
Dim dR As Object, dRs As Object, DK As Object
Set dR = CreateObject("scripting.dictionary")
Set dRs = CreateObject("scripting.dictionary")
Set DK = CreateObject("scripting.dictionary")
iRow = Sheet2.[a65536].End(xlUp).Row
Arr = Sheet2.Range("a1:f" & iRow)
ReDim Brr(2 To iRow, 0)
i = 2
Mn = Arr(i, 2): Mx = Arr(i, 2)
For i = 2 To iRow
If Not DK.exists(Arr(i, 1)) Then DK(Arr(i, 1)) = DK.Count
dR(Arr(i, 2)) = ""
If Arr(i, 2) > Mx Then Mx = Arr(i, 2)
If Arr(i, 2) > Mn Then Mn = Arr(i, 2)
Next i
Dkey = dR.keys
j = 0
For i = Mn To Mx
If dR.exists(i) Then j = j + 1: dRs(i) = j
Next i
ReDim Hrr(1 To dRs.Count, 0 To DK.Count - 1)
For i = 2 To iRow
Hrr(dRs(Arr(i, 2)), DK(Arr(i, 1))) = i
Next i
For j = 0 To DK.Count - 1
Dkey = Empty
For i = 1 To dRs.Count
k = Hrr(i, j)
If k > 0 Then
If Arr(k, 3) < Arr(k, 4) Then
Dkey = Dkey = 1: Brr(k, 0) = Dkey
Else
Dkey = 0
End If
End If
Next i
Next j
Sheet2.[f2].Resize(UBound(Brr) - 1, 1) = Brr
End Sub
运行时错误9下标越界帮我优化
|
|