Formula help.

Dan Wilson

Well-known Member
Joined
Feb 5, 2006
Messages
546
Office Version
  1. 365
Platform
  1. Windows
Good day. I am running Excel out of Office365 (updated) and Windows 10 Home (Updated). I have a workbook that tracks all of the songs in my music library. One of the worksheets is used to generate 40 random numbers between 1 and 3000. The worksheet titled "50-69" contains several Columns dedicated to the identification of each song in the library. Column A contains the song title. Row 1 contains the Column headers and is set as the "Freeze Top Row" for the worksheet. Thus, Rows 2 through 3000 identify each song. There is a separate worksheet titled "Sheet 1" that creates the random numbers in 40 separate cells as show below.

1​
2​
3​
4​
5​
6​
7​
8​
9​
10​
2611​
268​
2587​
2023​
348​
1505​
127​
1795​
2926​
1433​
11​
12​
13​
14​
15​
16​
17​
18​
19​
20​
1362​
604​
2034​
2901​
2268​
2979​
552​
550​
1454​
331​
21​
22​
23​
24​
25​
26​
27​
28​
29​
30​
187​
772​
201​
2438​
2786​
1961​
1392​
2883​
2117​
2050​
30​
32​
33​
34​
35​
36​
37​
38​
39​
40​
2443​
708​
1122​
691​
2976​
580​
2884​
2949​
1877​
2083​

In the example above, the numbers 1 thru 40 identify the order of the songs to be played. the numbers directly below them are the Row numbers of the worksheet "50-69" containing the 3000 songs. Thus, the first song to be played would be in Row 2611 with the song title in Column A. To make the whole process easier, I would like to create another set of numbers 1 thru 40 in a descending Column on the same worksheet with the order of 1 thru 40 in Column A and then fill column B with the actual song title from worksheet "50-69" as identified by the random number. I don't know how to search for a Row number in a formula and that is my problem. Any help will be appreciated.
Thank you,
Dan Wilson...
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hello, generally speaking would it for you e.g. to use SEQUENCE function to assign a number to each song, i.e. =SEQUENCE(3000), and then use XLOOKUP look for the song which corresponds to the assigned number?
 
Upvote 0
Here is a simple example. My way of making the random choice is not optimal

Cell Formulas
RangeFormula
B2:B19B2=LET(V,RANDBETWEEN(1,3000),IF(COUNTIF(B$1:B1,V)>0,IF(V+1>3000,1,V+1),V))
C2:C19C2=INDEX(Sheet2!A$2:A$3001,Sheet1!B2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:B41Cell ValueduplicatestextNO
 
Upvote 0
Good day Jeffrey and thank you for responding. After examining your reply, I see that your solution provides its own random numbers. A few months ago, I asked for help with the Random function and the solution works well. The formulas given to me create 40 separate random numbers anywhere from 1 to 3010 with no duplicates. What I need is a formula that will use the existing random numbers to search the "50-69" worksheet and return the song title found in Column A of the Row identified by the random number. I appreciate the help, and I hope that my explanation is complete.
Thank you,
Dan Wilson...
 
Upvote 0
My '50-69' has this sample data extending down to row 3000

Dan Wilson.xlsm
A
1Title
2Song 1
3Song 2
4Song 3
5Song 4
6Song 5
7Song 6
8Song 7
9Song 8
10Song 9
11Song 10
12Song 11
50-69


I'm assuming that 'Sheet1' has some sort of labelling & if that is so, perhaps you could use something like this?

Dan Wilson.xlsm
ABCDEFGHIJKLMNO
1
2Seq123456789101Song 2610
3Row26112682587202334815051271795292614332Song 267
43Song 2586
5Seq111213141516171819204Song 2022
6Row1362604203429012268297955255014543315Song 347
76Song 1504
8Seq212223242526272829307Song 126
9Row18777220124382786196113922883211720508Song 1794
109Song 2925
11Seq3032333435363738394010Song 1432
12Row244370811226912976580288429491877208311Song 1361
1312Song 603
1413Song 2033
1514Song 2900
1615Song 2267
1716Song 2978
1817Song 551
1918Song 549
2019Song 1453
2120Song 330
2221Song 186
2322Song 771
2423Song 200
2524Song 2437
2625Song 2785
2726Song 1960
2827Song 1391
2928Song 2882
3029Song 2116
3130Song 2049
3231Song 2442
3332Song 707
3433Song 1121
3534Song 690
3635Song 2975
3736Song 579
3837Song 2883
3938Song 2948
4039Song 1876
4140Song 2082
Sheet1
Cell Formulas
RangeFormula
N2:N41N2=SEQUENCE(40)
O2:O41O2=INDEX('50-69'!A:A,TOCOL(IF(A2:A12="row",B2:K12,1/0),2))
Dynamic array formulas.


BTW, sample data you gave would be better with XL2BB so we could see what rows/columns the data is in (& possibly any row/column headings). :)
 
Last edited:
Upvote 0
Good day Peter_SSs and thank you for your response. I had already started working with the response from Jeffrey Mahoney before seeing your response. I will print out what you sent and play with it later. It does look interesting and who knows, I may learn something.
Thank you,
Dan Wilson...
 
Upvote 0
Use the Index formula I gave you. Replace SHEET2 with 50-69
Good day again Jeffrey. Outstanding!!! After playing with your formula, all is working! I modified the formula to the following:
=INDEX('50-69'!A:A,Sheet1!A4)
This way the formula checks all of the song entries, even after I add more to the worksheet. The "A4" element is then changed for each of the 40 entries. After accomplishing that, I then added a Column for each of the 40 entries to use the XLOOKUP function to access one of the Columns in the '50-69' worksheet that shows the last podcast number that the song was played in. My apologies for not recognizing that your formula was at the bottom of your first response and that it would work so well. Thank you again for the EXCELLENT help.
Dan Wilson...
 
Upvote 0
@Dan Wilson
Glad you have something that is working as you want. Just pointing out that with your version of Excel you should be able to produce all 40 results with a single formula, rather than 40 separate formulas.

@Dan Wilson ; @Jeffrey Mahoney
I would strongly recommend that you do not use the text Sheet1 in any formula that is on Sheet1. It is not necessary and can lead to incorrect results in some circumstances. For an example see/try the example here (looks like I have mentioned this to you before Jeffrey ;))

So instead of
=INDEX('50-69'!A:A,Sheet1!A4)
change to
=INDEX('50-69'!A:A,A4)
 
Upvote 0
@Dan Wilson
Glad you have something that is working as you want. Just pointing out that with your version of Excel you should be able to produce all 40 results with a single formula, rather than 40 separate formulas.

@Dan Wilson ; @Jeffrey Mahoney
I would strongly recommend that you do not use the text Sheet1 in any formula that is on Sheet1. It is not necessary and can lead to incorrect results in some circumstances. For an example see/try the example here (looks like I have mentioned this to you before Jeffrey ;))

So instead of
=INDEX('50-69'!A:A,Sheet1!A4)
change to
=INDEX('50-69'!A:A,A4)
Good day again Peter_SSs. I already took care of that. Thank you for the follow-up. This forum is absolutely great!
Dan Wilson...
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,109
Members
453,021
Latest member
Justyna P

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