-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChallenge.vba
49 lines (40 loc) · 1.12 KB
/
Challenge.vba
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
41
42
43
44
45
46
47
48
49
Sub tickertime()
'define variables
Dim ticker2 As Long
ticker2 = 2
LR = Cells(Rows.Count, 1).End(xlUp).Row
Dim total_volume As Double
total_volume = 0
Dim start As Long
start = 2
Dim percent As Double
'set values
For i = 2 To LR
total_volume = total_volume + Cells(i, 7).Value
'print values
If Cells(i + 1, 1).Value <> Cells(i, 1).Value Then
ticker = Cells(i, 1).Value
Cells(ticker2, 9).Value = ticker
Cells(ticker2, 10).Value = total_volume
'reseting to zero
total_volume = 0
ychange = Cells(i, 6) - Cells(start, 3).Value
If Cells(start, 3).Value > 0 Then
percent = 100 * ychange / Cells(start, 3).Value
Else
percent = 0
End If
If ychange > 0 Then
Cells(ticker2, 11).Interior.ColorIndex = 4
ElseIf ychange < 0 Then
Cells(ticker2, 11).Interior.ColorIndex = 3
Else
Cells(ticker2, 11).Interior.ColorIndex = 0
End If
start = i + 1
Cells(ticker2, 11).Value = ychange
Cells(ticker2, 12).Value = percent
ticker2 = ticker2 + 1
End If
Next i
End Sub