-
Notifications
You must be signed in to change notification settings - Fork 0
/
VBA HW Bonus Code.rtf
75 lines (74 loc) · 2.32 KB
/
VBA HW Bonus Code.rtf
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
75
{\rtf1\ansi\ansicpg1252\cocoartf2576
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fnil\fcharset0 HelveticaNeue;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\deftab560
\pard\pardeftab560\slleading20\partightenfactor0
\f0\fs26 \cf0 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}