|
- Sub 去重()
- Dim Conn As Object, Rst As Object
- Dim strConn As String, strSQL As String
- Dim i As Integer, PathStr As String
- Set Conn = CreateObject("ADODB.Connection")
- Set Rst = CreateObject("ADODB.Recordset")
- PathStr = ThisWorkbook.FullName
- Select Case Application.Version * 1
- Case Is <= 11
- strConn = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=excel 8.0;Data source=" & PathStr
- Case Is >= 12
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PathStr & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
- End Select
- strSQL = "Select 序号,max(日期)as 最近日期 From [svc$] group by 序号"
- Conn.Open strConn
- Set Rst = Conn.Execute(strSQL)
- With Sheets("check")
- .Range("a:e").Clear
- For i = 0 To Rst.Fields.Count - 1
- .Cells(1, i + 1) = Rst.Fields(i).Name
- Next i
- .Range("A2").CopyFromRecordset Rst
- .Cells.EntireColumn.AutoFit
- End With
- Rst.Close
- Conn.Close
- Set Conn = Nothing
- Set Rst = Nothing
- End Sub
复制代码 加个标题用SQL最简单。
|
|