|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Private Sub CommandButton1_Click()
- Dim cnn As Object, rs As Object, SQL$
- On Error Resume Next
- [a1].CurrentRegion.Offset(1, 0).Clear 'Contents
- Cells.ClearOutline
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider = Microsoft.ace.Oledb.12.0;Extended Properties =Excel 12.0;Data Source =" & ThisWorkbook.Path & "\数据来源.xlsm"
- SQL = "Select 公司,日期,cstr(编号),种类,费用 from [Sheet1$a2:m] where 日期 between #" & TextBox1.Text & "# And #" & TextBox2.Text & "# "
- Set rs = cnn.Execute(SQL)
- [a2].CopyFromRecordset rs
- cnn.Close
- Set cnn = Nothing
- Set rs = Nothing
- [a1].CurrentRegion.Select
- Selection.Sort Key1:=[a2], Order1:=xlAscending, Key2:=[d2], Order1:=xlAscending, Header:=xlYes
- Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(5), _
- Replace:=True, PageBreaks:=False, SummaryBelowData:=True
- End Sub
复制代码 |
|