|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub CC()
Sheet2.UsedRange.Offset(1).ClearContents
Set d = CreateObject("scripting.dictionary"): n = [f65536].End(3).Row
For i = 2 To n: d(Cells(i, "f").Value) = "": Next: kk = d.keys
strPath = ThisWorkbook.FullName
Select Case Application.Version * 1
Case Is <= 11
strConn = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=excel 8.0;Data source=" & strPath
Case Is >= 12
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strPath & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
End Select
Set cn = CreateObject("adodb.connection"): Set rs = CreateObject("adodb.recordset")
cn.Open strConn
For Each sjhm In kk
Sql = "select Top 10 * from [Sheet1$] where 手机号码='" & sjhm & "'"
If rs.State = 1 Then rs.Close
rs.Open Sql, cn, 1, 3
rowlast = Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1
Sheet2.Range("A" & rowlast).CopyFromRecordset rs
Next
End Sub |
|