我正在研究一个数据,其中我有一个公司名称列表,一个在另一个之下。例如
1. A
2. B
3. C
还有更多......
需要的结果是
1. A
2. A
3. A
4. A
5. A
6. B
7. B
8. B
9. B
10. B
11. C
12. C
13. C
14. C
15. C
依旧......
数据太大,无法手动执行此任务。因此,如果任何人都可以建议一个可以简化工作的公式,那就太好了。)
答案 0 :(得分:3)
答案 1 :(得分:2)
将数据复制到变量数组,并从中构建一个具有所需大小的新数据
Sub Demo()
Dim r As Range, v1 As Variant, v2 As Variant
Dim i As Long, j As Long, n As Long
n = 5 ' number of entries
With ActiveSheet
' Get existing data into array
Set r = .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
v1 = r.Value
' Create new array of required size
ReDim v2(1 To UBound(v1, 1) * n, 1 To 1)
' copy and replicate original data into new array
For i = 1 To UBound(v1, 1)
For j = 1 To n
v2((i - 1) * n + j, 1) = v1(i, 1)
Next j, i
' Place new data onto sheet
Set r = r.Resize(r.Rows.Count * n, 1)
r.Value = v2
End With
End Sub