Using AND & OR in VBA

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,564
Office Version
  1. 365
Platform
  1. Windows
In Excel a formula can be built to establish if a number of conditions are true or false such as
=IF(AND(A1=1,OR(A2=1,A3=1)),TRUE,FALSE)

So if A1=1, A2=1 & A3=0 then the result would be TRUE
Similarly if A1=1, A2=0, A3=1 then TRUE
Or if A1=1, A2=0, A3=0 then FALSE

How would this translate to VBA?

TIA
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,360
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Like this:

Code:
If Range("A1").Value2 = 1 And (Range("A2").Value2 = 1 Or Range("A3").Value2 =1) Then
' True part
Else
' False part
End If
 
Upvote 0

Forum statistics

Threads
1,190,757
Messages
5,982,755
Members
439,794
Latest member
rhonllanders

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
Top