Choosing a random entry from a range, ignoring errors and certain values?

fishoutofwater

New Member
Joined
Jul 20, 2011
Messages
38
I have a range A1:D40. There are all kinds of pieces of data in the range including: #n/a, 0, ....

In E1, I want to pick something random from the range, as long as it meets these criterion:

(1) LEN(ofpick)>5
(2) ISERROR(ofpick)= False

In other words if I have this:

A...................B.....................C
RiceMeal..........0....................#N/A
Oatmeal..........OhNo...............#N/A
Pumpkins.........#N/A...............Ice
#N/A..............Kittens.............Dog
#N/A..............22...................0
0...................Happiness.........BigMac
Soda..............Sunshine..........Sledding

I want to have some sort of command that looks like this:
RAND(A1:C7) IF cell has text lenght > 5
So, I'd want E1 to give me something random from:

RiceMeal
Oatmeal
Pumpkins
Happiness
Sunshine
BigMac
Sledding

since every other entry in the range is either too shart LEN or Is an #N/A error.

Is this possible?

ps. For some reason I only have RAND with my version of excel, so another constraint here is that I cannot use RANDBETWEEN :(
 
YAY!!!! HOORAY!!!!! IT WORKS IT WORK IT WORKS!!!!

THANKS BIFF!!

You have no idea how deeply, how totally, how sincerely I appreciate this help! Getting to make my idea go from just stuff in my head to a real excel thing that works is just beyod words... and something I'd never be able to do without the occasional help from you all here on mrexcel when things are over my head.

THANKS!!!!
You're welcome. Thanks for the feedback! :cool:
 
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)
Here's my attempt at the single column case, using named ranges dataRange (e.g. A2:A10) and dataCol (the whole column A:A)

=INDEX(dataCol, LARGE(IF(LEN(dataRange)>5,ROW(dataRange)), RANDBETWEEN(1,SUMPRODUCT(--(LEN(dataRange)>5)))),1)
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,777
Members
452,942
Latest member
VijayNewtoExcel

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