我正在尝试设置一个输入框,如果某个单元格(I4)中的值大于0,就会弹出输入框。然后我想这样做,这样如果没有在单元格中输入任何内容,它将提示用户输入信息。如果用户按下cancel,则宏应该停止。
Sub testing123()
Re_Enter_FileImport:
FileImport = InputBox("File Not Yet Imported, Please Provide Reasoning")
If Range("I4") <> 0 Then
Answer = FileImport
'Code if user pressed cancel
If StrPtr(FileImport) = 0 Then
Exit Sub
ElseIf FileImport = "" Then
MsgBox "Please Provide Reasoning"
GoTo Re_Enter_FileImport:
Else
End If
End Sub当我尝试此代码时,无论单元格I4中的信息是否为0,都会弹出输入框。另外,我如何定义输入用户答案的位置?
发布于 2019-08-15 05:15:02
您应该能够通过Do While循环来实现这一点,该循环将一直运行,直到用户输入值或按下cancel。此外,您还可以使用.Value属性将它们的答案放在需要的地方。
Sub testing123()
Dim FileImport As String
Dim AnsBool As Boolean
AnsBool = True
If Range("A4") > 0 Then
FileImport = InputBox("File Not Yet Imported, Please Provide Reasoning")
Do While AnsBool
If StrPtr(FileImport) = 0 Then Exit Sub
If FileImport <> "" Then Exit Do
MsgBox "Please Provide Reasoning"
FileImport = InputBox("File Not Yet Imported, Please Provide Reasoning")
Loop
End If
'You can change this to the range needed
Range("A1").Value = FileImport
End Subhttps://stackoverflow.com/questions/57498694
复制相似问题