|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test()
Dim arr(1 To 16 ^ 4, 1 To 2), crr(1 To 10, 1 To 4), x1&, x2&, x3&
Dim s&, y, i&, j&, k&, brr, x, m
With Sheets("sheet1")
For x1 = 1 To 20
For x2 = 1 To 30
For x3 = 1 To 20
.Range("L2") = x1
.Range("M2") = x2
.Range("N2") = x3
s = s + 1
y = .Range("P6")
arr(s, 1) = x1 & "," & x2 & "," & x3
arr(s, 2) = y
Next x3, x2, x1
brr = Application.WorksheetFunction.Transpose(Application.Index(arr, 0, 2))
For i = 1 To 10
x = Application.WorksheetFunction.Large(brr, i)
For j = 1 To s
If x = arr(j, 2) Then
m = Split(arr(j, 1), ",")
For k = 0 To UBound(m)
crr(i, k + 1) = m(k)
Next
End If
crr(i, 4) = x
Next j
Next i
End With
Sheets("Sheet2").Select
With Sheets("sheet2")
.Range("G1") = "L2"
.Range("H1") = "M2"
.Range("I1") = "N2"
.Range("J1") = "P6"
Range("G2").Resize(UBound(crr), UBound(crr, 2)) = crr
End With
End Sub
真郁闷我的附件怎么缩都超过1MB,没办法上传附件了,这个VBA的作用是赋值给L2,M2,N2经过复杂计算,得到P6的值,
然后得到最大的P6的值的十个结果,同时看到这十个结果对应的L2,M2,N2的值。如果是半年的数据,在整整计算一天,
这个VBA还有优化的空间吗?
|
|