How to repeat a value into rows based on another cells value in excel

二次信任 提交于 2019-12-13 01:14:17

问题


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:

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:

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).

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. Any help would be greatly appreciated.


回答1:


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:

       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:

=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.

To return the job role this was pretty easy when I have the ID numbers, the statement I used in cell C8 was:

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

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


来源:https://stackoverflow.com/questions/30347184/how-to-repeat-a-value-into-rows-based-on-another-cells-value-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!