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

我目前正在运行一个macros,其input框代码如下所示:

ActiveCell.Value = InputBox(Prompt:="Please enter the sample name", Title:="Sample name") 

这对我在ActiveCell中没有任何文本的情况非常有用,但是如果已经有了文本,它会清除文本,如果我点击取消。

我该如何改变这一点,如果我在这一步取消了取消,那么它会跳到下一步,而不是改变已经在单元格中的内容? 我不希望它结束​​子,我只是想要它跳到代码中的下一行。

感谢您的帮助。

这应该做的工作:

昏暗的string
 s = InputBox(提示:=“请input样品名称”,标题:=“样品名称”)
如果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