hqmtba 发表于 2015-1-27 23:24
细看发现了个细节问题,就是sheet1中的A列“异动类型”有四种情况:大额买单、大额卖单、单笔异涨、 ... - Sub test()
- Dim ar, br, cr(), i, k, n, s, d As Object, dd As Object
- On Error Resume Next
- Set d = CreateObject("scripting.dictionary")
- Set dd = CreateObject("scripting.dictionary")
- With Sheets("Sheet1")
- ar = .Range("A2:G" & .[A65536].End(xlUp).Row)
- End With
- ReDim cr(1 To UBound(ar), 1 To 5)
- For i = 1 To UBound(ar)
- cr(i, 1) = --Left(ar(i, 6), Len(ar(i, 6)) - 2)
- If ar(i, 1) = "大额买单" And ar(i, 5) < -3 / 100 And cr(i, 1) > 500 Then
- cr(i, 2) = "√"
- Else
- cr(i, 2) = ""
- End If
- If ar(i, 1) = "大额买单" And ar(i, 5) < -5 / 100 And cr(i, 1) > 500 Then
- cr(i, 3) = "√"
- Else
- cr(i, 3) = ""
- End If
- If ar(i, 1) = "大额买单" And cr(i, 1) > 1000 Then
- cr(i, 4) = "√"
- Else
- cr(i, 4) = ""
- End If
- If Not d.exists(ar(i, 1) & "," & ar(i, 3) & "," & ar(i, 6) & "," & ar(i, 7)) Then
- cr(i, 5) = ""
- d(ar(i, 1) & "," & ar(i, 3) & "," & ar(i, 6) & "," & ar(i, 7)) = ""
- s = cr(i, 1)
- If Not dd.exists(ar(i, 2) & "," & ar(i, 3)) Then
- If ar(i, 1) = "大额买单" Then
- dd(ar(i, 2) & "," & ar(i, 3)) = ar(i, 2) & "," & ar(i, 3) & "," & s & ",0,0,0," & s & ",0"
- ElseIf ar(i, 1) = "大额卖单" Then
- dd(ar(i, 2) & "," & ar(i, 3)) = ar(i, 2) & "," & ar(i, 3) & ",0," & s & ",0,0,0," & s
- End If
- Else
- br = Split(dd(ar(i, 2) & "," & ar(i, 3)), ",")
- If ar(i, 1) = "大额买单" Then
- br(2) = s + br(2): br(6) = Application.Max(s, br(6))
- ElseIf ar(i, 1) = "大额卖单" Then
- br(3) = s + br(3): br(7) = Application.Max(s, br(7))
- End If
- dd(ar(i, 2) & "," & ar(i, 3)) = Join(br, ",")
- End If
- Else
- cr(i, 5) = "a"
- End If
- Next i
- ReDim ar(1 To dd.Count, 1 To 8)
- For Each k In dd.keys
- br = Split(dd(k), ",")
- br(4) = br(2) - br(3)
- If Val(br(3)) = 0 Then
- br(5) = "无大卖单"
- Else
- br(5) = Round(br(2) / br(3), 2)
- End If
- n = n + 1
- For i = 1 To UBound(br) + 1
- ar(n, i) = br(i - 1)
- Next i
- Next
- Sheets("Sheet1").[H2].Resize(UBound(cr), 5) = cr
- With Sheets("结果")
- .UsedRange.Offset(1, 0).ClearContents
- .[A2].Resize(n, 8) = ar
- End With
- Set d = Nothing
- Set dd = Nothing
- End Sub
复制代码
|