分配名称而不重复

时间:2019-06-06 19:35:18

标签: excel random duplicates

我正在努力将一些代码随机分配到时间表中。

我有30名员工需要分配三次进,出和休息时间:早上,午餐和下午。

我想给员工分配一位。 即 米尔豪斯: 在早上 外出-下午 休息-午餐

到目前为止,我有: 工作表1-员工

__|____A_____|______B_____|____________C__________|______D______|
1_|  RANDOM  |    STAFF   |       GET NUMBER      |   VLOOKUP   |
2_|{=RAND()} | Homer      | =LARGE($A:$A,ROW(A1)) | Millhouse   |
3_|{=RAND()} | Bart       | =LARGE($A:$A,ROW(A1)) | Bart        |
4_|{=RAND()} | Millhouse  | =LARGE($A:$A,ROW(A1)) | Homer       |

列D为= VLOOKUP(C2,$ A $ 2:$ B $ 4,2,0)

如何将随机名称放入新工作表而不重复?

类似这样的东西:

__|______A________|______B______
1_|Morning In_____| Millhouse   
2_|Morning Out____| Bart
3_|Morning Break__| Homer
4_|
5_|Lunch In_______| Homer
6_|Lunch Out______| Millhouse
7_|Lunch Break____| Bart
8_|
9_|Afternoon In___| Bart
10|Afternoon Out__| Homer
11|Afternoon Break| Millhouse

希望这对外面的人有意义。

感谢您的关注, 山姆

1 个答案:

答案 0 :(得分:0)

我放弃了Excel并使用JavaScript开发。这是代码:

<html>

<style>
    table td{border: 1px solid #000}
    span.red{background: red;}
    span.orange{background: orange;}
    span.yellow{background: yellow;}
    span.green{background: green;}
    span.blue{background: blue;}
    span.purple{background: purple;}
    </style>

<body onload="populate();">

<table>
<tr><th>Inside</th><th>Outside</th><th>Break</th></tr>
<tr><td id="resultsA"></td><td id="resultsB"></td><td id="resultsC"></td></tr>
<tr><td id="resultsD"></td><td id="resultsE"></td><td id="resultsF"></td></tr>
<tr><td id="resultsG"></td><td id="resultsH"></td><td id="resultsI"></td></tr>
</table>

<script> 

//DATA SHUFFLER
function shuffle(a){
    for (let b = a.length - 1; b > 0; b--){
        const c = Math.floor(Math.random() * (b + 1));
        [a [b], a [c]] = [a [c], a[b] ];
        }
        return a;
    }

//DATA
var results = document.getElementById("results");

//DEFINED FOR LATER USE 
var inside = 8;
var outside = 8;
var rest = 8;

//DEFINE STAFF
var staff = [
"<span class='red'>01</span>",
"<span class='red'>02</span>",
"<span class='red'>03</span>",
"<span class='red'>04</span>",
"<span class='orange'>05</span>",
"<span class='orange'>06</span>",
"<span class='orange'>07</span>",
"<span class='orange'>08</span>",
"<span class='yellow'>09</span>",
"<span class='yellow'>10</span>",
"<span class='yellow'>11</span>",
"<span class='yellow'>12</span>",
"<span class='green'>13</span>",
"<span class='green'>14</span>",
"<span class='green'>15</span>",
"<span class='green'>16</span>",
"<span class='blue'>17</span>",
"<span class='blue'>18</span>",
"<span class='blue'>19</span>",
"<span class='blue'>20</span>",
"<span class='purple'>21</span>",
"<span class='purple'>22</span>",
"<span class='purple'>23</span>",
"<span class='purple'>24</span>"
];

//SHUFFLE DATA
shuffle(staff);

//SPLIT
function populate(){
    //SPLIT STAFF INTO A, B AND C
    var arrayA = staff.splice(0, 8); 
    var arrayB = staff.splice(0, 8); 
    var arrayC = staff.splice(0, 8);

    //OUTPUT FIRST ROW
    resultsA.innerHTML = arrayA;
    resultsB.innerHTML = arrayB;
    resultsC.innerHTML = arrayC;

    //SPLIT A, B AND C INTO A1 & A2,
    //B1 & B2 AND C1 & C2
    var arrayA1 = arrayA.splice(0, 4);
    var arrayA2 = arrayA.splice(0, 4);
    var arrayB1 = arrayB.splice(0, 4);
    var arrayB2 = arrayB.splice(0, 4);
    var arrayC1 = arrayC.splice(0, 4);
    var arrayC2 = arrayC.splice(0, 4);

    //DEFINE D, E AND F
    var arrayD = arrayB1 + arrayC2;
    var arrayE = arrayC1 + arrayA2;
    var arrayF = arrayA1 + arrayB2;

    //OUTPUT SECOND ROW
    resultsD.innerHTML = arrayD;
    resultsE.innerHTML = arrayE;
    resultsF.innerHTML = arrayF;    

    //DEFINE G, H AND I
    var arrayG = arrayC1 + arrayB2;
    var arrayH = arrayA1 + arrayC2;
    var arrayI = arrayB1 + arrayA2;

    //OUTPUT THIRD ROW
    resultsG.innerHTML = arrayG;
    resultsH.innerHTML = arrayH;
    resultsI.innerHTML = arrayI;
    }

    </script> 

</html>

如果有人能简化它,我将不胜感激。 谢谢 山姆