|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub A()
Dim cnn, rs As Object, Sql As String, arr, brr(1 To 9999, 1 To 2), i%, m%, T
Dim j%, s
s = Replace(Sheet2.Name, "沪深A股", "")
j = Application.Match(s + 0, Rows(1), 0)
Set cnn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.Recordset")
cnn.Open "Provider=Microsoft.ACE.OleDb.12.0;Extended Properties='Excel 12.0;HDR=YES'; Data Source=" & ThisWorkbook.FullName
Sql = "select distinct 细分行业 from [沪深A股20180731$a1:c] where 名称 is not null"
arr = cnn.Execute(Sql).getrows
Sql = "select 名称,细分行业,[涨幅%%] FROM [沪深A股20180731$a1:c] ORDER BY 2,3 desc"
rs.Open Sql, cnn, 1, 1
For i = 0 To UBound(arr, 2)
rs.Filter = "细分行业='" & arr(0, i) & "'"
For T = 1 To 5
If Not rs.EOF Then
m = m + 1
brr(m, 1) = arr(0, i)
brr(m, 2) = rs.Fields("名称")
rs.MoveNext
End If
Next
Next
[a2:z999] = ""
[a2].Resize(m, 1) = Application.Index(brr, 0, 1)
[a2].Offset(0, j - 1).Resize(m, 1) = Application.Index(brr, 0, 2)
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub |
|