У меня есть таблица с символами тикера (A), рабочими днями в течение года (B), значением открытия (C), высоким значением (D), низким значением (E), значением закрытия (F) иобъем (E).Данные располагаются в хронологическом порядке по рабочим дням и в алфавитном порядке по символу тикера.
Я пытаюсь создать во втором подпрограмме команду, которая вытягивает первый и последний номера строк с соответствующими символами тикера.Затем, используя эти номера строк, извлеките соответствующие значения открытия и закрытия для года, чтобы создать столбец ежегодных изменений.Я не получаю никаких ошибок из своего кода, но ежегодное изменение не дает правильного значения.Чего мне не хватает?
Sub TickerVolume()
' Set an initial variable for holding the ticker
Dim Ticker As String
'Create new column headers
Cells(1, 9).Value = "Ticker"
Cells(1, 10).Value = "Yearly Change"
Cells(1, 11).Value = "Percent Change"
Cells(1, 12).Value = "Total Stock Volume"
' Set an initial variable for holding the volume total
Dim Vol_Total As Double
Vol_Total = 0
' Keep track of the location for summary table
Dim Summary_Table_Row As Integer
Summary_Table_Row = 2
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
' Loop through all tickers
For i = 2 To LastRow
' Check if we are still within the same ticker, if it is not...
If Cells(i + 1, 1).Value <> Cells(i, 1).Value Then
' Set the Ticker
Ticker = Cells(i, 1).Value
' Add to the Volume Total
Vol_Total = Vol_Total + Cells(i, 7).Value
' Print the Ticker in the Summary Table
Range("I" & Summary_Table_Row).Value = Ticker
' Print the Vol to the Summary Table
Range("L" & Summary_Table_Row).Value = Vol_Total
' Add one to the summary table row for next ticker
Summary_Table_Row = Summary_Table_Row + 1
' Reset the Vol Total
Vol_Total = 0
' If the cell immediately following a row is the same Ticker...
Else
' Add to the Ticker Total
Vol_Total = Vol_Total + Cells(i, 7).Value
End If
Next i
End Sub
Sub YearlyChange()
' Find start and end rows with unique Ticker
Dim TickStartRow As Long
Dim TickEndRow As Long
Dim Summary_Table_Row As Integer
Summary_Table_Row = 2
LastRow1 = Cells(Rows.Count, 9).End(xlUp).Row
' Loop through all tickers
For i = 2 To LastRow1
'Find start and end rows
TickStartRow = Range("A:A").Find(what:=Cells(i, 9), after:=Cells(1,
1)).Row
TickEndRow = Range("A:A").Find(what:=Cells(i, 9), after:=Cells(1, 1),
SearchDirection:=xlPreivous).Row
' Print the Change in the Summary Table
Range("J" & Summary_Table_Row).Value = Range("C" & TickStartRow).Value -
Range("F" & TickEndRow).Value
' Add one to the summary table row for next ticker
Summary_Table_Row = Summary_Table_Row + 1
Next i
End Sub