简体   繁体   English

Excel:如何根据单元格值重复多个值 X 次,包括重复模式

[英]Excel: How to repeat multiple values based on a cell value X times, including a repeated pattern

I'm new to this forum so apologies if I haven't posted this question correctly.我是这个论坛的新手,如果我没有正确发布这个问题,我深表歉意。 Would really appreciate any help if possible.如果可能的话,真的很感激任何帮助。 Thanks in advance.提前致谢。 Data input in columns A - E and desired outcome in columns G - K (picture attached). A - E 列中的数据输入和 G - K 列中的预期结果(附图片)。

输入和期望的结果

Codes I have tired to edit my self but can't quite get it to work:我已经厌倦了编辑自己的代码,但不能完全让它工作:

Going through the steps logically:逻辑地完成这些步骤:

  1. Each "Folder" value needs to be repeated down by the number ((Quantity *5)+1) - Desired outcome shown in Column H. There are 11 No. "A" followed by 16 No. "B".每个“文件夹”值都需要向下重复数字((数量*5)+1)-H列中显示的期望结果。有11个“A”号,然后是16个“B”号。
  2. The "Sub-folder" value is repeated down, offset (1,0), repeated down by 5, then the next sequential number starts being repeated down again by 5 and so on... carries on 1,2,3 etc. Desired outcome in Column I. “子文件夹”值向下重复,偏移量(1,0),向下重复 5,然后下一个序列号开始再次向下重复 5,依此类推......继续 1,2,3 等。第 I 列中的预期结果。
  3. The "Document Type" value is repeated down, offset (2,0), repeated down by 4, then 1No. “文档类型”值向下重复,偏移量 (2,0),向下重复 4,然后是 1No。 blank cell and repeat down by 4 again.空白单元格并再次向下重复 4。 Desired outcome in Column J. J 列中的预期结果。
  4. The "Document Number" will always be 1, 2, or 3. the subsequent numbering should start offset (3,0), then 2No. “文档编号”将始终为 1、2 或 3。后续编号应从偏移量 (3,0) 开始,然后是 2No。 blank cells, then sequential numbering again 1 - 3.空白单元格,然后再次按顺序编号 1 - 3。

I am trying to create a document control system where the document names are identified before the project starts.我正在尝试创建一个文档控制系统,其中在项目开始之前识别文档名称。 The "Unique Document Number" includes a formula to give me the unique number. “唯一文件编号”包含一个公式,可以为我提供唯一编号。 The reason for the gaps is I can conditional format the cells into colours to identify headings and sub-headings.出现间隙的原因是我可以有条件地将单元格格式化为颜色以识别标题和子标题。

There could be 12 No. folders A - L and within them 6 sub-folders 001 - 006, making the list very long.可能有 12 个编号文件夹 A - L,其中有 6 个子文件夹 001 - 006,使列表很长。 Having recognised the pattern I feel this could be automated, but struggling.认识到这种模式后,我觉得这可以自动化,但很挣扎。

Regards问候

In an effort to solve this without VBA You need a couple of helper columns:为了在没有 VBA 的情况下解决这个问题,您需要几个辅助列:

P repetitions
P2 = E2
P3 = =IF(P2>1,P2-1,INDIRECT("E" & Q3))

Q row
Q2 = 2
Q3 = =IF(P2>1,Q2,Q2+1)

R First Sub Number Helper
R3 = 1
R4 = =IF(MOD(P4,5)>0,R3,R3+1)

Then to your table:然后到你的桌子:

G1 = =H2&IF(I2<>"","-"&I2,"")&IF(J2<>"","-"&J2,"")&IF(K2<>"","-"&K2,"")
H1 = A2
H2 = =IF(P2>1,H2,INDIRECT("A" & Q3))
I3 = R3
I4 = =IF(P4>P3,"",R4)
J2 = =IF(OR(I2="",MOD(P2,5)=0),"",XLOOKUP(H2,A:A,C:C))
K1 = =IFS(OR(J2="",MOD(P2,5)>3),"",MOD(P2,5)=3,1,MOD(P2,5)=2,2,MOD(P2,5)=1,3)

Drag down all columns as appropriate.根据需要向下拖动所有列。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM