重新格式化宏使其重复
问题描述:
我在网络上的其他地方找到了此代码,并将其调整为符合我的需求。重新格式化宏使其重复
我有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
答
我猜测问题是相关的代码不在循环内。 请参阅\请尝试以下操作:
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
'每105行重复'是指'rng'?如果您发现上述代码并对其进行了修改,则只需15分钟即可找到每x行重复的代码。 – findwindow
我一直在写for循环,使我能够自动化但不成功。我也无法整合现有的代码,这些代码会将现有代码重复x行。你有任何建议findwindow? – engineertoanalyst
'对于i = 1到5000步骤105',然后'Set rng = Sheet2.Range(“A”&i&“:B”&i + 104)' –