Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$G$2" Then Cells(14, "b").Resize(300, 11).ClearContents Dim CNN As New ADODB.Connection Dim RST As New ADODB.Recordset Dim strSql As String, DbPath DbPath = "provider=microsoft.jet.oledb.4.0;extended properties='Excel 8.0;HDR=NO';data source=" & ThisWorkbook.FullName CNN.Open DbPath strSql = "select top " & Val(Cells(2, "g")) & " * from [七年级总成绩册$H3:r300] order by f10" RST.Open strSql, CNN, adOpenKeyset, adLockPessimistic Cells(14, "b").CopyFromRecordset RST Set RST = Nothing CNN.Close End If End Sub
原来是在G2格输入N的值,显示“七年级总成绩册”中的前N名。
[此贴子已经被作者于2006-6-14 11:50:50编辑过] |