|
看了下,这个鬼大概要写ado,晚上再说吧。- Function getRst(ByVal strWhere As String) As Dictionary
- Dim cnn As New ADODB.Connection
- Dim rst As New ADODB.Recordset
- Dim dict As New Dictionary
- Dim strSQL As String
- Application.ScreenUpdating = False
-
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='excel 12.0;hdr=yes';Data Source=" & ThisWorkbook.FullName
- strSQL = "select 科目,sum(实际收费) as 收费合计 from [学员档案汇总$A2:AI699] where 季度='" & strWhere & "' group by 科目"
- rst.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
- Do Until rst.EOF
- dict.Add rst(0).Value, rst(1).Value
- rst.MoveNext
- Loop
-
- Set getRst = dict
- Set dict = Nothing
- rst.Close
- cnn.Close
-
- End Function
- Sub test()
- Dim dict As New Dictionary
- Set dict = getRst("19秋季")
- Sheets("科目数据").Range("C6").Resize(dict.Count, 1) = Application.Transpose(dict.Keys)
- Sheets("科目数据").Range("J6").Resize(dict.Count, 1) = Application.Transpose(dict.Items)
- End Sub
复制代码
其它的写法类似,这里就不再写了。这可能需要你花点时间去百度一下SQL语句。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|