重新格式化macros,以便重复
我在networking上的其他地方find了这个代码,并根据我的需要进行调整。
我有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