How to return a random cell value based on a condition

Gracy0101

New Member
Joined
Jun 28, 2020
Messages
2
Office Version
  1. 2010
Platform
  1. Windows
I am looking for a help with a formula in excel. I have two tabs in my excel
Updates:
Updates.PNG

One:
One.PNG


My input is in cell F1

When the input is 1, it should check if ID 1 is available in "updates" sheet and return a random "Code" from "updates Sheet" which has ID 1.

IF ID 1 is not available in Updates sheet, it should check in sheet "one" and return a random code from here which contains ID 1.

When Input is ID 3, it should check in sheet 'updates', ID 3 is not available in updates sheet, so it should go to sheet 'one' and return a random code which has ID 3.

Basically it should always check the 'updates' sheet first. only if the input ID is not available, it should go to 'One' Sheet.

My data here is dynamic,for example ID 1 values will keep increasing every month, so when a match is found it should return value. Please help on this.

This is the formula I have used, =INDEX(A:A,LARGE(IF(B:B=F1,ROW(B:B)-ROW(B2)+1),INT(RAND()*COUNTIF(B:B,F1)+1)))

My input(ID) is present in the F1 cell. However, this formula always returns the same code A2. However i need some random code each time.
 

Attachments

  • Updates.PNG
    Updates.PNG
    4.2 KB · Views: 7

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Book2
ABCDEFGHIJ
1CodeID1A9IDCODE
2A111G1
3A211G2
4A311G3
5A411G4
6A513F1
7A613F2
8A713F3
9A813F4
10A91
11W12
12L12
Sheet1
Cell Formulas
RangeFormula
G1G1=IF(COUNTIF(B:B,F1)>0,INDEX(OFFSET(A1,MATCH(F1,B:B,0)-1,0,COUNTIF(B:B,F1),1),RANDBETWEEN(1,COUNTIF(B:B,F1)),1),INDEX(OFFSET(I1,MATCH(F1,I:I,0)-1,1,COUNTIF(I:I,F1),1),RANDBETWEEN(1,COUNTIF(I:I,F1)),1))
 
Upvote 0
Book2
ABCDEFGHIJ
1CodeID1A9IDCODE
2A111G1
3A211G2
4A311G3
5A411G4
6A513F1
7A613F2
8A713F3
9A813F4
10A91
11W12
12L12
Sheet1
Cell Formulas
RangeFormula
G1G1=IF(COUNTIF(B:B,F1)>0,INDEX(OFFSET(A1,MATCH(F1,B:B,0)-1,0,COUNTIF(B:B,F1),1),RANDBETWEEN(1,COUNTIF(B:B,F1)),1),INDEX(OFFSET(I1,MATCH(F1,I:I,0)-1,1,COUNTIF(I:I,F1),1),RANDBETWEEN(1,COUNTIF(I:I,F1)),1))
Thank you, it worked
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,446
Members
449,083
Latest member
Ava19

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