Luka Miletic
Luka Miletic

Reputation: 1

Excel input pop up box if cell is false

I would like to make an excel worksheet to suit my needs of making word documents (mail merge).

Can I use IF function like this:

IF(A1=Specific text;Write this text;RUN MACRO with popup box to input other text)

Basically, if value is true - write pre defined text and if it is false - give me pop up box to input new text?

Upvotes: 0

Views: 2133

Answers (2)

markblandford
markblandford

Reputation: 3193

Yes you can, however I would not recommend it because each time the worksheet is calculated, if the result of your IF() statement is FALSE, the InputBox will be displayed.

However if you insist, try something like the following:

Cell Formula =IF(A1="Something","Result1", AskForResult())

In a Code Module, add the following:

Public Function AskForResult() As String
    Dim strUserResponse As String

    strUserResponse = InputBox("What result to give?")

    AskForResult = strUserResponse
End Function

This will display an InputBox like below when the value in A1 <> "Something"

enter image description here

Upvotes: 2

glh
glh

Reputation: 4972

Using a vba function you can. If your vba function was:

function test() as string

    Test = Inputbox("Enter value")

End function

Usage:

=if(A1="value", "value1", test)

Upvotes: 0

Related Questions