|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub test()
Dim cnn As Object
Dim rs As Object
Dim MySQL As String
Dim sht As Worksheet
Set cnn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
Set d = CreateObject("scripting.dictionary")
cnn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.FullName
With Sheets("原表")
r = .Cells(.Rows.Count, 1).End(3).Row
For i = 2 To r
yf = Month(.Cells(i, 9))
If Not d.exists(yf) Then
MySQL = "select * from [原表$] where month(列9)='" & yf & "'"
rs.Open MySQL, cnn, 1, 3
Sheets.Add
ActiveSheet.Name = yf & "月"
For j = 0 To rs.Fields.Count - 1
Cells(1, j + 1) = rs.Fields(j).Name
Next
ActiveSheet.Range("A2").CopyFromRecordset rs
MySQL = ""
d(yf) = ""
rs.Close
End If
Next
End With
End Sub
|
评分
-
1
查看全部评分
-
|