[英]How to repeat a value into rows based on another cells value in excel
In my worksheet I have the following data that tells me how many people are in a certain job role using a =countif() statement from another worksheet:在我的工作表中,我有以下数据,使用另一个工作表中的 =countif() 语句告诉我有多少人在某个工作角色中:
Job Role|Amount of people in the role
Job 1 | 6
Job 2 | 26
Job 3 | 4
Now I have done is in my worksheet I have used Job 1, Job 2 and Job 3 as headings to 3 separate tables below this table like this:现在我完成的是在我的工作表中,我使用了工作 1、工作 2 和工作 3 作为该表格下方 3 个单独表格的标题,如下所示:
Job Role|Amount of people in the role
Job 1 | 6
Job 2 | 26
Job 3 | 4
Job 1 Job 2 Job3
Name|Job Role Name|Job Role Name|Job Role
All I would like to do at the moment is to populate each of the 3 tables with the job role based on the amount that is in the top table, for example, under the Job 1 table, I would like the job role to repeat 6 times (I cannot just type this in because I want this to work automatically just in case another employee gets added to the employee list I have).我现在想要做的就是根据顶部表中的数量用工作角色填充 3 个表中的每一个,例如,在工作 1 表下,我希望工作角色重复 6次(我不能只输入这个,因为我希望它自动工作,以防万一另一名员工被添加到我拥有的员工列表中)。
Job 1
Name|Job Role
1 |Job 1
2 |Job 1
3 |Job 1
4 |Job 1
5 |Job 1
6 |Job 1
and the same for job 2 (which will have 26 repeated rows) and job 3 which will have 4 rows.作业 2(将有 26 行重复)和作业 3(将有 4 行)相同。 Any help would be greatly appreciated.任何帮助将不胜感激。
Just in case anybody is curious I have solved this.以防万一有人好奇,我已经解决了这个问题。 First of all I figured out that I could add a ROW ID for each row of data in each job 1, job 2 and job 3 tables and make it so that it would not go over the amount of people stated in the top table like this:首先,我发现我可以为每个作业 1、作业 2 和作业 3 表中的每一行数据添加一个 ROW ID,并使其不会像这样超过顶部表中规定的人数:
A B C
1 Job Role|Amount of people in the role |
2 Job 1 | 6 |
3 Job 2 | 26 |
4 Job 3 | 4 |
5
6 Job 1
7 ID |Name |Job Role
8 1 |t |
9 2 |b |
10 3 |a |
11 4 |s |
12 5 |d |
13 6 |f |
To get the number to go to 6 and not go over this, i used this formula (IN CELL A8) to automatically give the row an ID if an employee is taken away or added:为了让数字转到 6 而不是越过这个,我使用这个公式(IN CELL A8)在员工被带走或添加时自动为该行提供一个 ID:
=IF(ROW()-7>B2,"",ROW()-7)
This statement basically says "if the row number -7 is HIGHER than B2 (6 in the table), then leave a blank space, if the row number is LOWER then B2 then return the row number -7 = 1 and when pulled down this will carry on until 6 and then start to leave blank spaces unless another employee of the Job 1 job role is added which in case case it will go up to 7.此语句基本上是说“如果行号 -7 高于 B2(表中的 6),则留一个空格,如果行号较低,则 B2 则返回行号 -7 = 1,当下拉此将一直持续到 6 点,然后开始留空白,除非添加了工作 1 工作角色的另一名员工,以防万一它会增加到 7 点。
To return the job role this was pretty easy when I have the ID numbers, the statement I used in cell C8 was:要返回工作角色,当我有 ID 号时这很容易,我在单元格 C8 中使用的语句是:
=IF(A8<>"",A6,"")
This basically means that if the ID column has something in it then return the Job Role so I end up with what I want:这基本上意味着,如果 ID 列中有内容,则返回工作角色,因此我最终得到了我想要的:
Job 1
ID | Name |Job Role
1 | T |Job 1
2 | B |Job 1
3 | A |Job 1
4 | S |Job 1
5 | D |Job 1
6 | F |Job 1
you must use power query您必须使用电源查询
You can simply add a column with this formula:您可以简单地使用此公式添加一列:
=Text.Repeat("a",[column with repeated times]) =Text.Repeat("a",[重复次数列])
In column 5 should be the count you want for rows to be duplicated.第 5 列应该是您想要复制的行数。
Then, from transform tab, split the new column by number of characters, use 1 char split, but from advanced settings, make sure you split into rows, not into columns, this will duplicate all other columns.然后,从转换选项卡,按字符数拆分新列,使用 1 个字符拆分,但从高级设置中,确保拆分为行,而不是列,这将复制所有其他列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.