Easy inequality if/then statement...

Engineer Joe

Well-known Member
Joined
Jun 10, 2005
Messages
543
For some reason, I can't seem to make this junk work...here's what i'm trying to do. I have to input values (A and B). I'd like make an if statement that operates only if the values of BOTH A and B were input (i.e. not skipped over. The input is done in a textbox in a userform. This if/then statement is also excecuted at commandbutton_click() by the way.) I thought that this would work, but it isn't

Code:
If Not (A ="" or B="") then
blah, blah blah

What is the best way to indicate that A is not equal to nothing or "" or has been defined????

thanksesseseseses
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi Engineer Joe,

It looks like your statement should work properly.

But I'm assuming that A and B are string variables that are set like this:

A = TextBox1.Text

and that the TextBoxes indeed are initialized with a null string. If initialized with any other string (even a single space, as in " "), you should test for that string. If for example, your textboxes were initialized with "(enter dollar value here)" then the test would become:

If Not (A ="(enter dollar value here)" Or B="(enter dollar value here)") Then

or equivalently

If A <> "(enter dollar value here)" Or B <> "(enter dollar value here)" Then


I hope this helps.

Damon
 

Engineer Joe

Well-known Member
Joined
Jun 10, 2005
Messages
543
thanks...you won't believe this...but it's been so long since i've written any vba that i forgot the <> sign.... :unsure:
 

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi again Joe,

I think I goofed on that last "or equivalently" code. The OR should have been an AND.

Damon
 

Watch MrExcel Video

Forum statistics

Threads
1,119,128
Messages
5,576,259
Members
412,709
Latest member
Rishu
Top