Sub test
Dim ws As Worksheet: Set ws = ActiveWorkbook.Sheets(“GL”)
Dim xInput As Date, found As Range
xInput = Application.InputBox(“Enter Friday date”, Type:=1)
If IsDate(xInput) Then
Set found = ws.Range(“F:F”).Find(xInput, searchdirection:=xlPrevious)
If found Is Nothing Then
‘Need code to have user try again
Else
found.Offset(1).EntireRow.Insert (xlShiftDown)
End If
Else
‘Need code to have user try again
End if
End sub
现在我有只退出sub的代码,但是我需要代码帮助,该代码将在其中插入另一个InputBox再次尝试。
答案 0 :(得分:0)
您可以使用下面的Loop
,也可以使用FormatDateTime
来获取InputBox
的日期格式
Option Explicit
Sub NextFriday()
Dim FridayDate As Date
Do
FridayDate = Application.InputBox("Enter Friday's Date :", "Date Selection", FormatDateTime(Date, vbShortDate), Type:=1)
If Not IsDate(FridayDate) Then MsgBox "Error, not a Date format"
Loop Until IsDate(FridayDate)
End Sub