|
请帮助修改一下宏,谢谢!
运行宏,在AJ2单元格给出结果,但因为R3:AH52区域数据是公式生成的,所以目前的宏给出的结果是错误的。
正确的结果应该是 2,7,3,10 。
请修改一下宏,能在不去除R3:AH52区域内公式的基础上得出正确的结果。
Sub matching()
Dim arr, arr1, arr2, arr3, i%, j%, k&, l, m&, n&, p&, q&, s
n = [R65536].End(xlUp).Row
p = [Q1]
arr = Range("R3:AH" & n)
ReDim arr1(1 To 17)
ReDim arr2(1 To 17)
For k = 1 To 17
For l = 1 To n - 3
If arr(l, k) > 0 Then
arr1(k) = arr1(k) + 1
End If
Next l
Next k
For k = 1 To 17
If arr1(k) = Application.Max(arr1) Then i = k '最大列号
Next
s = i
For j = 1 To [Q1] - 1
For k = 1 To 17 '求与最大列号匹配次数
For l = 1 To n - 3
If arr(l, k) > arr(l, i) And arr(l, i) = 0 Then
arr2(k) = arr2(k) + 1
End If
Next l
Next k
For k = 1 To 17
If arr2(k) = Application.Max(arr2) Then '最大列号
m = k
Exit For
End If
Next
s = s & "," & m
For l = 1 To n - 3
If m = i Then Exit For
If arr(l, i) < arr(l, m) And arr(l, i) = 0 Then
arr(l, i) = arr(l, m)
arr(l, m) = 0
End If
Next l
ReDim arr2(1 To 17)
Next j
Range("AJ" & [AJ65536].End(xlUp).Row + 1) = s
End Sub
修改.rar
(23.42 KB, 下载次数: 5)
|
|