0

我想通过使用 VBA 获取大数组的每 4 行来从大数组创建一个较小的数组
我已将大数组定义为 dist_in = Range("A3.B903") 我如何循环遍历该数组以创建第二个大批?

谢谢,唐


4

2 回答 2

0

Quick&dirty - 使用单元格来引用原始和新区域 - 第 4 和 5 列将是 D & E - 更改数字以适应。

Sub ShrinkIt()

Dim i as long

for i=1 to 225
    cells(i,4)=cells(i*4-1,1)
    cells(i,5)=cells(i*4-1,2)
next i

End Sub
于 2012-06-21T19:55:01.110 回答
0
Sub MakeBigArraySmall()

    Dim vaLarge As Variant
    Dim aSmall() As Variant
    Dim i As Long, j As Long
    Dim lCnt As Long

    'Read in array
    vaLarge = Sheet1.Range("A3:B903").Value

    'set up small array
    ReDim aSmall(1 To (UBound(vaLarge, 1) \ 4) + 1, 1 To UBound(vaLarge, 2))

    'loop through large and write every 4th value to small
    For i = LBound(vaLarge, 1) To UBound(vaLarge, 1) Step 4
        lCnt = lCnt + 1
        For j = LBound(vaLarge, 2) To UBound(vaLarge, 2)
            aSmall(lCnt, j) = vaLarge(i, j)
        Next j
    Next i

    'write small array back out to sheet
    Sheet1.Range("D3").Resize(UBound(aSmall, 1), UBound(aSmall, 2)).Value = aSmall

End Sub
于 2012-06-22T15:48:03.603 回答