How to make an OR() statement with n conditions, based on the count of an input array?

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
528
Office Version
  1. 365
Platform
  1. Windows
Hello,

Suppose I want to test if a particular cell, say B2, is equal to any one of a few numbers or not, such as below:
=IF(OR(B2=10,B2=11,B2=12),operation_if_true,operation_if_false)

However, the number of the conditions may not always be 3, so I need to create an expression that automatically generates an OR() statement with the number of conditions matching the count of an input array; perhaps something like below:
=LET(x,{10,11,12,13,etc.},y,formula_to_generate_OR_with_n_conditions,IF(y,operation_if_true,operation_if_false))

I got stuck trying to code for "formula_to_generate_OR_with_n_conditions". I was thinking possibly MAP or MAKEARRAY?

Thanks for any input! 🤗
 
P.S. I was trying to apply Stephen's formula to ranges, and it wasn't spilling, so I incorporated it into MAP:

=MAP(B2:D2,LAMBDA(a,OR(a={10,11,12})))

This works well with ranges and spills.
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Yes, I'm always learning something new from this forum, on a daily basis. Since Stephen is on this thread, I should say he has been super helpful along the way.

But I wish I knew more VBA like you. It's so powerful! So I'm kind of in the other end of the spectrum compared to you. I can write some complex formulas, but practically not much VBA 😅 But glad to have VBA experts on here!
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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