打印左列数X倍数Excel

时间:2012-02-15 18:47:27

标签: excel

enter image description here

我知道=rept函数会重复一定数量xy次,但数字都在同一行,有没有办法让它每次都重复一次?

这张图片只是为了让我知道我在说什么。

1 个答案:

答案 0 :(得分:1)

你可以选择一个范围,输入一个数字并点击 ctrl + 输入,它会为你填写。那是你想要做的吗?


VBA

当x是活动单元格旁边的单元格时,此VBA将采用活动单元格并将其复制x次

Sub InsertSome()
    Application.ScreenUpdating = False
    Dim n As Integer
    n = ActiveCell(, 2)
    For i = 1 To n
        ActiveCell.Copy
        ActiveCell.Insert shift:=xlDown
        ActiveCell(2, 2).Insert shift:=xlDown
    Next i
    Application.ScreenUpdating = True
End Sub

如果您需要将其插入1次,因为活动单元格是计数的一部分,只需将其更改为For i=1 to (n-1)