Vba 如果在InputBox中按了取消,则跳到下一步

Vba 如果在InputBox中按了取消,则跳到下一步,vba,excel,inputbox,Vba,Excel,Inputbox,我当前正在运行一个宏,输入框代码如下所示: ActiveCell.Value = InputBox(Prompt:="Please enter the sample name", Title:="Sample name") 当我在ActiveCell中没有任何文本时,它非常有用,但是如果已经有文本,如果我点击cancel,它会清除文本 我怎样才能改变它,如果我在这一步点击cancel,它就会跳到下一步,而不会改变单元格中已经存在的内容?我不希望它结束sub,我只希望它跳到代码中的下一行 谢谢您

我当前正在运行一个宏,输入框代码如下所示:

ActiveCell.Value = InputBox(Prompt:="Please enter the sample name", Title:="Sample name")
当我在ActiveCell中没有任何文本时,它非常有用,但是如果已经有文本,如果我点击cancel,它会清除文本

我怎样才能改变它,如果我在这一步点击cancel,它就会跳到下一步,而不会改变单元格中已经存在的内容?我不希望它结束sub,我只希望它跳到代码中的下一行


谢谢您的帮助。

这应该可以完成以下工作:

Dim s as String s = InputBox(Prompt:="Please enter the sample name", Title:="Sample name") If s <>"" Then ActiveCell.Value = s 像线一样变暗 s=输入框(提示:=“请输入样本名称”,标题:=“样本名称”) 如果是s“”,则ActiveCell.Value=s
这应该可以做到:

Dim s as String s = InputBox(Prompt:="Please enter the sample name", Title:="Sample name") If s <>"" Then ActiveCell.Value = s 像线一样变暗 s=输入框(提示:=“请输入样本名称”,标题:=“样本名称”) 如果是s“”,则ActiveCell.Value=s 试试这个:

Dim a As Variant
a = Application.InputBox(Prompt:="Please enter name", Title:="Sample name")
If a <> False Then
    ActiveCell.Value = a
End If
Dim a作为变体
a=应用程序.InputBox(提示:=“请输入名称”,标题:=“样本名称”)
如果是假的话
ActiveCell.Value=a
如果结束
试试这个:

Dim a As Variant
a = Application.InputBox(Prompt:="Please enter name", Title:="Sample name")
If a <> False Then
    ActiveCell.Value = a
End If
Dim a作为变体
a=应用程序.InputBox(提示:=“请输入名称”,标题:=“样本名称”)
如果是假的话
ActiveCell.Value=a
如果结束

这仍然不起作用。它只是删除了单元格中的内容,然后像以前一样继续。请再次检查-粘贴时重要的
丢失-我更新了我的答案。是的,就是这样!非常感谢你的帮助。那仍然不起作用。它只是删除了单元格中的内容,然后像以前一样继续。请再次检查-粘贴时重要的
丢失-我更新了我的答案。是的,就是这样!非常感谢你的帮助。