A few questions about randomizing arrays while avoiding doubles...

kingsushi001

New Member
Joined
Oct 24, 2017
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
Hi Everyone

I seem to be having problems and I just can't figure it out. Been googling a few days now without any clear answer.

I have this sheet:
ColorsExample.xlsx
ABCD
1Primary ColorPrimary HEXSecondary ColorSecondary HEX
2Magenta
3Green
4Red
5Yellow
6Yellow
7Blue
8Green
9Red
10Yellow
11Red
12Blue
13Green
14Yellow
15Yellow
16Magenta
17Magenta
18Blue
19Cyan
20Red
main
Cell Formulas
RangeFormula
A2:A20A2=INDEX(color,RANDBETWEEN(1,ROWS(color)),1)


The Colors in column A are pulled from an array (color) on this sheet:
ColorsExample.xlsx
AB
1ColorsHEX
2Blue0000FF
3Cyan00FFFF
4Green00FF00
5MagentaFF00FF
6RedFF0000
7YellowFFFF00
col


Now my problem is that I need the HEX corresponding to the color in A from the array to be in column B, but seeing as column A is random, the HEX column gets all messed up and I have no idea how to fix it.

My second problem is that it needs to be done for Primary Color/HEX AND Secondary Color/HEX, except that the values for Secondary Color cannot be the same as for Primary Color.
Meaning that if for instance A2 is Green, the value for C2 can't be green as well, it needs to either choose the next value in line, or a new random one.

If anyone can help me out with this, it would be greatly appreciated as I'm losing sleep over this ?
 
I would suggest turning the lookup table on sheet 'col' into a formal Excel table (Insert tab -> Table) as shown below. I have renamed my table (done through the Formulas tab - Name Manager) to tblClrs

kingsushi001.xlsm
AB
1ColorsHEX
2Blue0000FF
3Cyan00FFFF
4Green00FF00
5MagentaFF00FF
6RedFF0000
7YellowFFFF00
8
col


Then you could use these in the 'main' tab.

Cell Formulas
RangeFormula
A2:A20A2=INDEX(tblClrs[Colors],RANDBETWEEN(1,ROWS(tblClrs[Colors])))
B2:B20,D2:D20B2=VLOOKUP(A2,tblClrs,2,0)
C2:C20C2=INDEX(tblClrs[Colors],AGGREGATE(15,6,(ROW(tblClrs[Colors])-ROW(tblClrs[#Headers]))/(ROW(tblClrs[Colors])-ROW(tblClrs[#Headers])<>MATCH(A2,tblClrs[Colors],0)),RANDBETWEEN(1,ROWS(tblClrs[Colors])-1)))
This is exactly what I needed. I see the table method works way faster than the array method.

Thank you very much!
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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