|
chyidc 发表于 2013-12-6 19:52
感谢赵老师前面的代码,是我自己表述有误了。
我的意思是想在text2的表下面,增加text1中的数据,日期比 ...
请测试:- Sub Getdate()
- Dim cnn As Object, rs As Object, SQL As String
- Set cnn = CreateObject("adodb.connection")
- Set rs = CreateObject("adodb.recordset")
- cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.Path & "\text1.xlsx"
- SQL = "select " & Join([a1:h1&""], ",") & " from [Sheet1$] where 日期>#" & Range("a" & Rows.Count).End(xlUp) & "#"
- rs.Open SQL, cnn, 1, 3
- If rs.RecordCount > 0 Then
- SQL = "select 日期,count(*) from [Sheet1$] where 日期>#" & Range("a" & Rows.Count).End(xlUp) & "# group by 日期"
- Range("a" & Rows.Count).End(xlUp).Offset(1).CopyFromRecordset rs
- Set rs = CreateObject("adodb.recordset")
- rs.Open SQL, cnn, 1, 3
- For i = 1 To rs.RecordCount
- s = s & vbCrLf & rs.Fields(0).Value & "更新" & rs.Fields(1).Value & "条"
- rs.MoveNext
- Next
- MsgBox s
- End If
- rs.Close
- cnn.Close
- Set rs = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
|