gpt4 book ai didi

excel - 错误处理不工作 VBA

转载 作者:行者123 更新时间:2023-12-04 20:43:42 24 4
gpt4 key购买 nike

如果找不到您要查找的内容,我正在尝试将用户循环回来。到目前为止我有这个,但是我如何循环返回让用户重新输入信息并用 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/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com