# VBA equaivalent of the IF worksheet functions

#### andyandy12345

##### New Member
I am trying unsuccessfully to work through a range where I need two conditions to be met and to output result that has to be looked up. In Excel the formula would look something like this "=IF(AND(X2<>"text", G2<>24),4,"x") - but this is limited for my requirements.

The value in x2 will be 1 of two possible text strings (eg text 1 or text 2)and the vaule in g2 will be 1 of 4 possible integers (eg 4,8,16,24) and I am trying to get the combination of x2 and g2 to output a values from a defined list

so if x2 = "text 1" and g2 = "24" then lookup/match to a list (i have tried using arrays, and can create them but cannot tap into using the stored values) and output an integer (possible results = 4 for each text strings)

Sorry if this is not clear but this explanation may indicate that I do not think logically enough to work out the vba..!

TIA

### Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
try like this

Code:
``if range("x2").value = "text 1" and range("g2!).value = 24 Then``

Thanks, not quite getting it to work like you suggest jsut yet, is there a way to use the If condition1 and contion 2 to lookup/match a pedefined list or array?

Is G2 to be compared against a list? If so where is that list?

both condtions in column x range and column g range need to be checked to determine result

range for column x will only contain "text 1" or "text 2"
range for column g will only contain numerical value 0,4,8,16 or 24

examples:

if x2 = "text 1" and g2 = 24 then result = 4

OR

if x2 = "text 2" and g2 = 24 then result = 5

Hope this explains...

Thank you

No it doesn't. What numerical value constitutes a match?

the only inputs with desired results are:

column x coulmn g Result
text 1 0 0
text 1 4 1
text 1 8 2
text 1 16 3
text 1 24 4
text 2 0 0
text 2 4 1
text 2 8 3
text 2 16 4
text 2 24 5

sorry that lost its format
under column x there are just text 1 or text 2
under column g there are just 0 0r 4 or 8 or 16 or 24

each of these possible 10 combinations will have the result under the result colum.

Replies
3
Views
199
Replies
1
Views
216
Replies
11
Views
319
Replies
14
Views
620
Replies
10
Views
327

1,221,005
Messages
6,157,342
Members
451,416
Latest member
mosteanuv

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back