-
Notifications
You must be signed in to change notification settings - Fork 0
/
VBA Bonus Code
74 lines (48 loc) · 1.99 KB
/
VBA Bonus Code
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Sub Bonus():
For Each ws In Worksheets
Dim greatestincrease As Double
Dim greatestdecrease As Double
Dim tickerdecrease As String
Dim greateststockvolume As Double
Dim BonusRows As Variant
Dim tickervolume As String
Dim tickerincrease As String
BonusRows = Array("Greatest % Increase", "Greatest % Decrease", "Greatest Total Volume")
greatestincrease = ws.Cells(2, 11).Value
greatestdecrease = ws.Cells(2, 11).Value
greateststockvolume = ws.Cells(2, 12).Value
tickerincrease = ws.Cells(2, 9).Value
tickerdecrease = ws.Cells(2, 9).Value
tickervolume = ws.Cells(2, 9).Value
LastRow_PercentChange = ws.Cells(Rows.Count, 11).End(xlUp).Row
LastColumn = ws.Cells(1, Columns.Count).End(xlToLeft).Column
ws.Cells(2, LastColumn + 3).Value = BonusRows(0)
ws.Cells(3, LastColumn + 3).Value = BonusRows(1)
ws.Cells(4, LastColumn + 3).Value = BonusRows(2)
LastColumn = ws.Cells(2, Columns.Count).End(xlToLeft).Column
ws.Cells(1, LastColumn + 1).Value = "Ticker"
ws.Cells(1, LastColumn + 2).Value = "Value"
For i = 2 To LastRow_PercentChange
If greatestincrease < ws.Cells(i, 11).Value Then
greatestincrease = ws.Cells(i, 11).Value
tickerincrease = ws.Cells(i, 9).Value
End If
If greatestdecrease > ws.Cells(i, 11).Value Then
greatestdecrease = ws.Cells(i, 11).Value
tickerdecrease = ws.Cells(i, 9).Value
End If
If greateststockvolume < ws.Cells(i, 12).Value Then
greateststockvolume = ws.Cells(i, 12).Value
tickervolume = ws.Cells(i, 9).Value
End If
Next i
ws.Cells(2, 17).Value = greatestincrease
ws.Cells(2, 17).NumberFormat = "0.00%"
ws.Cells(3, 17).Value = greatestdecrease
ws.Cells(3, 17).NumberFormat = "0.00%"
ws.Cells(4, 17).Value = greateststockvolume
ws.Cells(2, 16).Value = tickerincrease
ws.Cells(3, 16).Value = tickerdecrease
ws.Cells(4, 16).Value = tickervolume
Next ws
End Sub