-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomework 02 MODERATE_ClosingDiff.bas
61 lines (51 loc) · 1.7 KB
/
Homework 02 MODERATE_ClosingDiff.bas
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
Attribute VB_Name = "Module1"
Option Explicit
Sub MODERATE_ClosingDiff()
Dim i As Double
Dim List_Row As Double
Dim Vol_Total As Double
Dim LastRow As Double
Dim Abbrev As String
Dim Opening As Double
Dim Closing As Double
Dim Difference As Double
Dim Percent As Double
Dim ws As Worksheet
For Each ws In Worksheets
ws.Activate
Vol_Total = 0
Range("J1") = "Ticker Abbrev"
Range("K1") = "Difference"
Range("L1") = "Percent"
Range("M1") = "Volume Total"
List_Row = 2
Opening = Cells(2, 3).Value
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, 1) <> Cells(i + 1, 1) Then
Abbrev = Cells(i, 1).Value
Closing = Cells(i, 6).Value
Difference = Closing - Opening
If Opening = 0 Then
Percent = ((Closing / 1) - 1) * 100
ElseIf Difference <> 0 Then
Percent = ((Closing / Opening) - 1) * 100
Else: Percent = 0
End If
Range("J" & List_Row).Value = Abbrev
Range("K" & List_Row).Value = Difference
If Percent > 0 Then
Range("K" & List_Row).Interior.ColorIndex = 10
ElseIf Percent < 0 Then
Range("K" & List_Row).Interior.ColorIndex = 30
End If
Range("L" & List_Row).Value = Percent
Range("M" & List_Row).Value = Vol_Total
Opening = Cells(i + 1, 3).Value
List_Row = List_Row + 1
Vol_Total = 0
Else
Vol_Total = Vol_Total + Cells(i, 7).Value
End If
Next i
Next ws
End Sub