-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2014 VBA Script.vb
40 lines (30 loc) · 1.25 KB
/
2014 VBA Script.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Sub StockTest_2014()
Dim ticker As String
Dim yearlyChange As Double
Dim percentChange As Double
Dim totalVolume As Double
yearlyChange = 0
percentChange = 0
totalVolume = 0
summaryTableRow = 2
For i = 2 To 705714
If Cells(i + 1, 1).Value <> Cells(i, 1).Value Then
ticker = Cells(i, 1).Value
yearlyChange = yearlyChange + (Cells(i, 6).Value - Cells(i, 3).Value)
percentChange = percentChange + ((Cells(i, 6).Value - Cells(i, 3).Value) / Cells(i, 3).Value)
totalVolume = totalVolume + Cells(i, 7).Value
Range("I" & summaryTableRow).Value = ticker
Range("J" & summaryTableRow).Value = yearlyChange
Range("K" & summaryTableRow).Value = percentChange
Range("L" & summaryTableRow).Value = totalVolume
summaryTableRow = summaryTableRow + 1
yearlyChange = 0
percentChange = 0
totalVolume = 0
Else
yearlyChange = yearlyChange + (Cells(i, 6).Value - Cells(i, 3).Value)
percentChange = percentChange + ((Cells(i, 6).Value - Cells(i, 3).Value) / Cells(i, 3).Value)
totalVolume = totalVolume + Cells(i, 7).Value
End If
Next i
End Sub