|
- Sub qs()
- Dim Sql$, line&, i&, arr
- Application.ScreenUpdating = False
- Set cnn = CreateObject("adodb.connection")
- Set rst = CreateObject("ADODB.RecordSet")
- With cnn
- .Open "Provider=Microsoft.Ace.oledb.12.0;extended properties='excel 12.0;HDR=yes';data source=" & ThisWorkbook.FullName
- Sql = "select 序号,班级,座号,小组,标记,姓名,得分,IIF( 积分 IS NULL, 0, 积分) as 积分 from [数据$a:h] ORDER BY 班级 ASC, 小组 ASC,得分 DESC"
- End With
- rst.Open Sql, cnn, 1, 3
- fldCount = rst.Fields.Count
- RowCount = rst.RecordCount
- ReDim headers(1 To fldCount)
- For i = 1 To fldCount
- headers(i) = rst.Fields(i - 1).Name
- Next i
- ReDim arr(1 To RowCount, 1 To fldCount)
- rst.MoveFirst
- For i = 1 To RowCount
- For j = 1 To fldCount
- If IsNull(rst.Fields(j - 1).Value) Then
- arr(i, j) = 0
- Else
- arr(i, j) = rst.Fields(j - 1).Value
- End If
- Next j
- rst.MoveNext
- Next i
- s = ""
- For i = 1 To UBound(arr)
-
- If s <> arr(i, 2) & "|" & arr(i, 4) Then
- r = i
- arr(r, 8) = 1
-
- Else
- If arr(i, 7) = arr(i - 1, 7) Then arr(i - 1, 8) = 0
-
- End If
- s = arr(i, 2) & "|" & arr(i, 4)
- Next
- Sheet2.Range("j1").Resize(1, UBound(arr, 2)) = headers
- Sheet2.Range("j2").Resize(UBound(arr), UBound(arr, 2)) = arr
- rst.Close: cnn.Close
- Set rst = Nothing: Set cnn = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|