vba 将重复 X 次并由计数器增加的公式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5196316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:12:56  来源:igfitidea点击:

Formula that will repeat number X times and increased by a counter

excelexcel-vbaexcel-2007vba

提问by wootscootinboogie

I have the following problem: I need to repeat a given number, say 3 times. I then need to repeat the next number the same amount of times. So I need a formula to print, for instance, 111, 222, 333, 444 etc. each on a different row. Can this be done? Thanks.

我有以下问题:我需要重复给定的数字,比如 3 次。然后我需要重复下一个数字相同的次数。所以我需要一个公式来打印,例如,111、222、333、444 等,每个都在不同的行上。这能做到吗?谢谢。

回答by Mark Baker

So something like:

所以像:

A1 =REPT(1,3)      // Initial number set to 1, repeated 3 times to give 111
A2 =REPT(LEFT(A1,LEN(A1)/3)+1,3)
A3 =REPT(LEFT(A2,LEN(A2)/3)+1,3)

etc

等等

回答by Marc

Still not 100% sure what you're trying to accomplish. But in the scenario where you want to see:

仍然不能 100% 确定您要完成的任务。但是在你想看到的场景中:

111,222,...,101010,111111,...,999999,100100100,101101101,...

111,222,...,101010,111111,...,999999,100100100,101101101,...

You could just copy this formula down the column:

您可以将此公式复制到列中:

=REPT(ROW(),3)

=REPT(ROW(),3)

ROW() returns the current row, so you might have to do a little math to make it produce your number. I.e. if you want "111" to appear in row #2, "=REPT(ROW()-1,3)"

ROW() 返回当前行,因此您可能需要做一些数学运算才能使其生成您的数字。即,如果您希望“111”出现在第 2 行,“=REPT(ROW()-1,3)”

If that's not what you're looking for, please be more explicit.

如果这不是您要查找的内容,请更明确。

回答by EroSan

Try on A1 =REPT(1+FLOOR(COLUMN()-1,3)/3,3)and then drag to all other columns... hopefully this is what you wanted if I understood correctly from the comments.

尝试使用 A1 =REPT(1+FLOOR(COLUMN()-1,3)/3,3),然后拖动到所有其他列...如果我从评论中正确理解,希望这就是您想要的。