我在网络上的其他地方找到了这个代码,并根据我的需要对其进行了调整。
我有20000行要经过。如何修改此代码以重复每105行,并将结果放在与前一行相隔的相同列中。我还需要以百分比格式逐行数据。
Sub SumSectorWeight()
Dim rng As Excel.Range
Dim arrProducts() As String
Dim i As Long
Set rng = Sheet2.Range("A" & i & ":B" & i + 104)
arrProducts = getSumOfCountArray(rng)
Sheet2.Range("E1:E1").Value = Array("Sector", "Sector Weight")
' go through array and output to Sheet2
For i = 2 To 5000 Step 105
Sheet2.Cells(i + 2, "E").Value = arrProducts(0, i)
Sheet2.Cells(i + 2, "F").Value = arrProducts(1, i)
Next
End Sub
答案 0 :(得分:0)
我猜测问题是相关代码不在循环内部。 请参阅\尝试以下内容:
Sub SumSectorWeight()
Dim Rng As Excel.Range
Dim arrProducts() As String
Dim i As Long
Sheet2.Range("E1:E1").Value = Array("Sector", "Sector Weight")
' go through array and output to Sheet2
For i = 2 To 5000 Step 105
Set Rng = Sheet2.Range("A" & i & ":B" & i + 104)
arrProducts = getSumOfCountArray(Rng)
Sheet2.Cells(i + 2, "E").Value = arrProducts(0, i)
Sheet2.Cells(i + 2, "F").Value = arrProducts(1, i)
Next
End Sub