mercredi 14 août 2019

How to have an input box pop up in VBA only if certain criteria is met?

I'm attempting to set up an input box that will come up if the value in a certain cell (I4) is greater than 0. I then want to make it so that if nothing is entered in the cell it will prompt the user to enter information. If the user presses cancel, then the macro should stop.

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

When I try this code, the Input Box pops up no matter if the info in cell I4 is 0 or not. Also, how do I define where the user's answer will be entered?

Aucun commentaire:

Enregistrer un commentaire