|
- Sub test1() '将表1中的 - 全部替换为 空
- Dim Conn As Object, ar, i As Integer
- Dim strConn As String, SQL As String
- Set Conn = CreateObject("ADODB.Connection")
- If Application.Version < 12 Then
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
- End If
- Conn.Open strConn & ThisWorkbook.FullName
- Worksheets("Sheet2").Activate
- Range("A1").CurrentRegion.Offset(2).ClearContents
- ar = Range("A1").CurrentRegion.Resize(2)
- SQL = "SELECT " & ar(2, 1)
- For i = 2 To UBound(ar, 2)
- If Len(ar(1, i)) Then SQL = SQL & ",NULL" Else SQL = SQL & ",AVG(" & ar(1, i - 1) & "分数)"
- Next
- SQL = SQL & " FROM [Sheet1$A2:AK] GROUP BY " & ar(2, 1)
- Range("A3").CopyFromRecordset Conn.Execute(SQL)
- Conn.Close
- Set Conn = Nothing
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|