如果找不到您要查找的内容,我正在尝试将用户循环回来。到目前为止我有这个,但是我如何循环返回让用户重新输入信息并用 MsgBox
提示他们也?
Range("A1").Select
Repeat:
Findcata = InputBox("Please Input What Section You Want To Add To")
If Findcata = "" Then Exit Sub
Set RangeObj = Cells.Find(What:=Findcat, After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If RangeObj Is Nothing Then GoTo Repeat Else: RangeObj.Select
最佳答案
下面的方法使用Application.Inputbox
哪个
MsgBox
的方法要清楚有重试我整理了
Select
, Find
逻辑也是如此。Dim strIn As String
Dim strNew As String
Dim rng1 As Range
Repeat:
strIn = Application.InputBox("Please Input What Section You Want To Add To (Cancel Exits)", strNew, "Default value", , , , , 2)
If strIn = vbNullString Or strIn = "False" Then Exit Sub
Set rng1 = Cells.Find(strIn, ActiveSheet.[a1], xlValues, xlPart, xlByRows, xlNext, False)
If rng1 Is Nothing Then
strNew = "Value not found, please retry"
GoTo Repeat
End If
关于excel - 错误处理不工作 VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25393623/