Combined IF, AND, OR statements

tasos8282

New Member
Joined
Jan 8, 2014
Messages
9
Hi everyone

I am quite new to VBA and have a seemingly simple question, yet I've been stuck for a few hours...

How could such a statement be written in VBA?

IF(AND(A1="yes"; OR(A2<50; A2>70)); "not allowed"; "something")

Thanks in advance for helping out!
T.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,

Use the MacroRecorder to get the proper syntax and go from there.
 
Upvote 0
Code:
Sub test()

If Range("A1") = "yes" Then
    If Range("A2") > 50 Or Range("A2") < 70 Then
        'do something
    Else
        'do something else
    End If
End If


End Sub
 
Upvote 0
The recorder is not able to do if and or statements unless your trying to put a formula in a cell and I don't think that's what you want.
Here is an excel Vba example
Code:
If Cells(1, 1).Value = "George" And Cells(1, 2).Value = "Bob" Or Cells(1, 3).Value = "Mary" Then
Cells(1, 4).Value = "Yes"
Else
Cells(1, 4).Value = "Nope"
End If
 
Upvote 0
Thank you all for your replies! I will test them all and see which one fits better, nevertheless it is good to have more ways than one to proceed and learn...

T.
 
Upvote 0

Forum statistics

Threads
1,214,854
Messages
6,121,941
Members
449,056
Latest member
denissimo

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