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: 15

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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