|
![](https://clubstatic.excelhome.net/image/common/ico_lz.png)
楼主 |
发表于 2017-2-17 15:25
|
显示全部楼层
Sub 获取指定科目成绩最高及最低分()
Dim mydata As String
Dim mytable As String
Dim sql As String
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Integer
ActiveSheet.Cells.Clear
mydata = ThisWorkbook.Path & "\成绩管理.mdb"
mytable = "考试成绩"
Set cnn = New ADODB.Connection
With cnn
.Provider = "microsoft.jet.oledb.4.0"
.Open mydata
End With
sql = "select max(数学) as math1,min(数学) as math2 from " & mytable
Set rs = New ADODB.Recordset
rs.Open sql, cnn, adOpenKeyset, adLockOptimistic
Range("a2:b1") = Array("数学最高分", "数学最低分")
Range("a2:b2") = Array(rs!math1, rs!math2)
rs.Close: cnn.Close
Set cnn = Nothing: Set rs = Nothing
End Sub
|
|