|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 蒙蒙烟雪 于 2015-1-28 00:27 编辑
这几天在学ADO, 试着写了下, 貌似速度不咋地 (想不出怎么一次性提取字段证券代码,只好掺杂一个字典, 巨汗 - -||| )
附表.rar
(114.98 KB, 下载次数: 10)
- Sub test()
- tt = Timer
- Sheet3.UsedRange.Offset(1, 0).ClearContents
- Sheet1.[f:f].Replace "万元", ""
- Dim conn As Object, SQL$, MyFile$, rs As Object, PVDR$
- Dim d As Object, Arr, r&, n&
- Set d = CreateObject("scripting.dictionary")
- Set conn = CreateObject("ADODB.Connection")
- Set rs = CreateObject("ADODB.Recordset")
- If Application.Version = "11.0" Then
- PVDR = "Provider=Microsoft.JET.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source="
- Else
- PVDR = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
- End If
- MyFile = ThisWorkbook.FullName
- SQL = "SELECT """",证券名称,SUM(IIF(异动类型='大额买单',单笔成交,0)) AS 大额买和,SUM(IIF(异动类型='大额卖单',单笔成交,0)) AS 大额卖和,"""","""",Max(IIF(异动类型='大额买单',单笔成交,0)) AS 最大买单,Max(IIF(异动类型='大额卖单',单笔成交,0)) AS 最大卖单 FROM [Sheet1$A1:F] GROUP BY 证券名称"
- conn.Open PVDR & MyFile
- Set rs = conn.Execute(SQL)
- Sheet3.[A2].CopyFromRecordset rs
- conn.Close
- Set conn = Nothing
- n = Sheet3.Cells(Rows.Count, 2).End(xlUp).Row
- Arr = Sheet1.[a1].CurrentRegion
- For r = 2 To UBound(Arr)
- d(Arr(r, 3)) = Arr(r, 2)
- Next
- For r = 2 To n
- Cells(r, 1) = d(Cells(r, 2).Value)
- Next
- Set d = Nothing
- Range("e2:e" & n).FormulaR1C1 = "=rc[-2]-rc[-1]"
- Range("f2:f" & n).FormulaR1C1 = "=rc[-3]/rc[-2]"
- [f:f].SpecialCells(xlCellTypeFormulas, 16) = "无大卖单"
- MsgBox Timer - tt
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|