Private Sub CommandButton1_Click()
Dim R, TT$, N&
R = Cells(Rows.Count, 1).End(xlUp).Row
For i = R To 2 Step -1
If Cells(i, 1) <> "" Then
TT = Cells(i, 1) & IIf(TT = "", "", vbCrLf) & TT
N = N + 1: If N = 5 Then Exit For
End If
Next i
TT = "最後幾筆資料是:" & vbCrLf & TT
If N > 0 Then MsgBox TT & String(2, Chr(10)) & "本周的周數是:" & DatePart("ww", Now, vbMonday)
End Sub作者: y54161212 時間: 2020-12-21 17:44
Sub test()
i = Split("Provider=Microsoft.,Jet.OLEDB.4,.0;Extended Properties=Excel ,8,.0;Data Source=", ",")
If Application.Version > 12 Then i(1) = "ACE.OLEDB.12": i(3) = 12
Set cn = CreateObject("adodb.connection"): cn.Open Join(i, "") & ThisWorkbook.FullName
q = "select top 5 * from[sheet1$A1:A]where LotNo is not NULL order by LotNo desc "
MsgBox Join(Application.Index(cn.Execute(q).getrows, 1, 0), Chr(10))
End Sub