PFost
PFost

Reputation: 61

And operator in VB

I am trying to program some VB code to display an error message if someone selects an licensing option from a drop down menu but does not indicate a quantity.

When they select the licensing option, it populates a cell with a defined name of FSValue . Right next to that is another cell to specify the quantity, called FSQuantity. The default value for FSValue is blank (empty), and the default value for FSQuantity is zero.

If they select an option from the dropdown menu and populate the FSValue cell, but do not indicate a quantity, I would like to display an error message.

This is the code I am trying to use (I have tried several iterations of this, using both the defined cell names and cell locations):

If (FSValue = "") And (FSQuantity = 0) Then
     MsgBox ("Please Enter a Value Quantity")
     Range("F47").Select
     Exit Sub
End If

I've also tried with nested if statements such as:

If FSValue = "" Then
    If FSQuantity=0 Then
        MsgBox ("Please Enter a Quantity")
        Range("F47").Select
        Exit Sub
    End if
End if

Nothing is working and it doesn't seem like it should be that difficult. Any help would be greatly appreciated.

Upvotes: 0

Views: 52

Answers (2)

Joel Coehoorn
Joel Coehoorn

Reputation: 415735

If they select an option from the dropdown menu and populate the FSValue cell, but do not indicate a quantity, I would like to display an error message.

FSValue = "" 

Look at those things together. At this point, they have selected a value. FSValue is no longer blank. You want this:

FSValue <> ""

Upvotes: 2

DanielG
DanielG

Reputation: 1675

You may want to wrap your tests in an NZ function,

If Nz(FSValue,"") = "" Then If Nz(FSQuantity,0) = 0 Then MsgBox ("Please Enter a Quantity") Range("F47").Select Exit Sub End if End if

Upvotes: 0

Related Questions