我想在下面的代碼中實現一個控件,只允許帶有mm/dd/yyyy格式的日期,並防止在輸入框中輸入空格。我試着添加一些代碼,但仍然遇到錯誤。第一個檢查它是否空白的控件有效,但是第二個控件如果Not似乎只是被忽略。如何限制輸入框輸入僅限日期
'Updates the report date located in report generation tab cell B8
Dim ws1 As Worksheet
Set ws1 = Sheets("Report Generation")
ReTry:
With ws1
Dim rptdate As Variant
rptdate = InputBox("Please Enter the Report Date *Must be EOM format mm/dd/yyyy*", "Enter Date")
If rptdate = "" Then
MsgBox ("You did not enter a date!"), vbCritical, Error
GoTo ReTry
If Not IsDate(rptdate) Then
MsgBox ("You did not enter the correct format!"), vbCritical, Error
GoTo ReTry
End If
Else
Range("B8").Value = rptdate
End If
End With
試試'elseif'代替? – findwindow
你知道究竟在哪裏嗎?遇到問題,如果我通過elseif或第二個替換第一個。 – UnbrokenChain
啊!如果在查看elseif語法之後,我將它添加到第二個。謝謝! – UnbrokenChain