VBA equaivalent of the IF worksheet functions

andyandy12345

New Member
Joined
Feb 26, 2011
Messages
11
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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
try like this

Code:
if range("x2").value = "text 1" and range("g2!).value = 24 Then
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,484
Members
452,917
Latest member
MrsMSalt

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top