Private Sub CommandButton1_Click()
Dim 最後列號, 組合字串$, 符合條件筆數&, 當下時間 As Date, 週$, 起算日
最後列號 = Cells(Rows.Count, 1).End(xlUp).Row
For i = 最後列號 To 2 Step -1
If Cells(i, 1) <> "" Then
組合字串 = Cells(i, 1) & vbCrLf & 組合字串
符合條件筆數 = 符合條件筆數 + 1: If 符合條件筆數 = 5 Then Exit For
End If
Next i
週 = "ww"
當下時間 = Now
起算日 = vbMonday
組合字串 = "最後幾筆資料是:" & vbCrLf & Mid(組合字串, 1, Len(組合字串) - 1)
If 符合條件筆數 > 0 Then MsgBox 組合字串 & String(2, Chr(10)) & "本周的周數是:" & DatePart(週, 當下時間, 起算日)
End Sub