我们正在使用 VBA 脚本。任务是遍历数据集中的几张表,汇总两个不同的列,然后将其打印到已经存在的数据旁边的列中。
当我运行代码时,似乎什么都没有发生。没有错误消息弹出,调试器也没有接收到任何东西。
代码
Sub Stock()
Dim ticker As String
Dim volume As Double
volume = 0
Dim WS_Count As Integer
Dim i As Integer
Dim summary_table_row As Integer
summary_row_table = 2
'Set worksheet count
WS_Count = ActiveWorkbook.Worksheets.Count
'Loop through each year of stock
For i = 2 To WS_Count
'Keep track of the years for each stock
If ActiveCell.EntireColumn.Cells(i + 1, 1).Value <> ActiveCell.EntireColumn.Cells(i, 1).Value Then
'Set ticker
ticker = ActiveCell.EntireColumn.Cells(i, 1).Value
'Set volume
volume = volume + ActiveCell.EntireColumn.Cells(i, 7).Value
'Print ticker
Range("J" & summary_table_row).Value = ticker
'Print volume
Range("K" & summary_table_row).Value = volume
summary_table_row = summary_table_row + 1
volume = 0
Else
volume = volume + ActiveCell.EntireColumn.Cells(i, 7).Value
End If
Next i
End Sub
请指出我的方向,以弄清楚发生了什么?