ak47ok 发表于 2014-10-11 11:03
通过近期夜以继日的运算,想更进一步提高效率,在最后加插了2列数据,麻烦老师看看如何修改代码,谢谢! - Sub test()
- Dim arr, d, i%, j%, brr, s$, k1$, k2$, k3$, c As Range, c1 As Range
- Set d = CreateObject("scripting.dictionary")
- With Sheets("sheet1")
- If Len(.Cells(2, 1)) = 0 Then GoTo br
- On Error Resume Next
- .Range(.Range("a65536").End(xlUp), .Range("ai1").End(xlDown)).SpecialCells(2, 1).ClearContents
- On Error GoTo 0
- Set c = .Columns("al").Find(.Range("a2"), lookat:=xlWhole, SearchDirection:=1)
- Set c1 = .Columns("al").Find(.Range("a2"), lookat:=xlWhole, SearchDirection:=2)
- If c Is Nothing Then
- br:
- MsgBox "A2单元格数据输入错误!"
- Exit Sub
- End If
- arr = .Range(.Range("ai1"), .Range("a65536").End(xlUp))
- brr = .Range(c, .Cells(c1.Row, 73))
- k1 = .Range("bs1"): k2 = .Range("bt1"): k3 = .Range("bu1")
- na = Application.CountA(.Range(.Range("a1"), .Range("ag1")))
- End With
- Set c = Nothing
- Set c1 = Nothing
- For i = 1 To UBound(brr)
- For j = 3 To na + 1
- d(brr(i, 2) & arr(1, j - 1)) = brr(i, j)
- Next
- d(brr(i, 2) & k1) = brr(i, 34)
- d(brr(i, 2) & k2) = brr(i, 35)
- d(brr(i, 2) & k3) = brr(i, 36)
- Next
- Erase brr
- For i = 10 To UBound(arr)
- For j = 2 To na
- s = arr(i, 1) & arr(1, j)
- If d.exists(s) Then
- If InStr(arr(1, j), "反") = 0 Then
- arr(i, j) = IIf(d(s) > arr(2, j), 1, 0)
- Else
- arr(i, j) = IIf(d(s) < arr(2, j), 1, 0)
- End If
- End If
- Next
- arr(i, 33) = d(arr(i, 1) & k1)
- arr(i, 34) = d(arr(i, 1) & k2)
- arr(i, 35) = d(arr(i, 1) & k3)
- Next
- Set d = Nothing
- Sheets("sheet1").Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
- End Sub
复制代码 |