这是一个拙劣的VBA解决方案。这假设“重复计数”位于第一行(4,2,3),“重复值”位于第二行(5,4,3,0,1,2)。
Sub outputRepeatedValues()
Dim xStart As Integer, yStart As Integer
Dim i As Integer, j As Integer
Dim valueToRepeat As Integer, numTimesRepeat As Integer
Dim xOffset As Integer, yOffset As Integer
xStart = ActiveCell.Column
yStart = ActiveCell.Row
i = 1
j = 1
xOffset = 0
yOffset = 0
While Cells(2, j) <> ""
If Cells(1, i) = "" Then
i = 1
yOffset = yOffset + 1
xOffset = 0
End If
numTimesRepeat = Cells(1, i)
valueToRepeat = Cells(2, j)
For k = 1 To numTimesRepeat
Cells(yStart + yOffset, xStart + xOffset) = valueToRepeat
xOffset = xOffset + 1
Next k
j = j + 1
i = i + 1
Wend
End Sub
把它放在一个新模块中。要使用此代码,请选择代表输出区域左上角的单元格。然后按Alt + F8调出宏框,然后可以运行宏。
如果您不知道如何插入VBA代码:http://www.contextures.com/xlvba01.html#Regular – AureliusPhi 2014-10-31 16:27:28