Skip to content

Commit

Permalink
Completed Sub3 VBA analysis, Finalized Readme and images
Browse files Browse the repository at this point in the history
  • Loading branch information
jhustles committed Mar 18, 2020
1 parent 874b8da commit e123434
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 13 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Wall Street Stock Data Analysis Using VBA

![stock Market](images/stockmarket.jpg)

## Project Goal:

Using my VBA scripting skills to analyze real stock market data over 2014, 2015, 2016 stock data.


## VBA Script Takes The Actions:

* Created a script that loops through each year of stock data and grab the total amount of volume each stock had over the year
Expand All @@ -18,3 +25,21 @@


* Locate the stock with the "Greatest % increase", "Greatest % Decrease" and "Greatest total volume".


## Output Results After Implementing VBA Script

![Screenshot of 2014 Results](images/VBA_2014_Stock_Mkt_Screenshot.JPG)

![Screenshot of 2015 Results](images/VBA_2015_Stock_Mkt_Screenshot.JPG)

![Screenshot of 2016 Results](images/VBA_2016_Stock_Mkt_Screenshot.JPG)


## Author

* **Johneson Giang** - *Individual Project* - [Github](https://github.com/jhustles)

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
107 changes: 94 additions & 13 deletions VBA_Script_JG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Sub Analysis_1()
End Sub



Sub Analysis_2()

'Performed:
Expand All @@ -74,20 +75,20 @@ Sub Analysis_2()

'Set up the loops thru all WORKSHEETS
For Each ws In Worksheets

'Declare all variables and define them
'Declare all variables and define them
Dim Ticker As String
Dim TotalOpenPrice As Double
Dim TotalClosePrice As Double
Dim Yearly_Change As Double
Dim Percent_Change As Double

'define the variables within each wksht
TotalStkVol = 0
TotalOpenPrice = 0
TotalClosePrice = 0
Yearly_Change = TotalClosePrice - TotalOpenPrice

Dim SummaryTableTick2 As Integer
SummaryTableTick2 = 2

Expand All @@ -96,7 +97,7 @@ Sub Analysis_2()
ws.Cells(1, 10).Value = "Yearly Change"
ws.Cells(1, 11).Value = "Percent Change"
ws.Cells(1, 12).Value = "Total Stock Volume"

lastrow = ws.Cells(Rows.Count, 1).End(xlUp).Row

'setting up the for loop and conditionals
Expand All @@ -113,8 +114,8 @@ Sub Analysis_2()
TotalClosePrice = TotalClosePrice + ws.Cells(Row, 6).Value
TotalYearlyChange = (TotalClosePrice - TotalOpenPrice)
TotalStkVol = TotalStkVol + ws.Cells(Row, 7).Value

'Print Ticker Name in the Summary Table
'Print Ticker Name in the Summary Table
ws.Range("I" & SummaryTableTick2).Value = Ticker

'Print "YEARLY CHANGE" to Summary Table
Expand All @@ -141,8 +142,9 @@ Sub Analysis_2()
'Change format for Total Percentage Change to Percent style
ws.Range("K" & SummaryTableTick2).Style = "Percent"
End If

'Print the TotalStkVol to the Summary Table


'Print the TotalStkVol to the Summary Table
ws.Range("L" & SummaryTableTick2).Value = TotalStkVol

'add one to the summary table row
Expand All @@ -166,6 +168,8 @@ Sub Analysis_2()

End Sub



Sub Analysis_3()

'Performed: locate the stock with the: "Greatest % increase", "Greatest % Decrease" and "Greatest total volume"
Expand Down Expand Up @@ -200,8 +204,7 @@ Sub Analysis_3()

lastrow = ws.Cells(Rows.Count, 1).End(xlUp).Row


'setting up the for loop and conditionals
'setting up the for loop and conditionals
For Row = 2 To lastrow

If ws.Cells(Row + 1, 1).Value <> ws.Cells(Row, 1).Value Then
Expand All @@ -218,7 +221,7 @@ Sub Analysis_3()

'Print Ticker Name in the Summary Table
ws.Range("I" & SummaryTableTick2).Value = Ticker

'Print "YEARLY CHANGE" to Summary Table
ws.Range("J" & SummaryTableTick2).Value = TotalYearlyChange

Expand All @@ -242,4 +245,82 @@ Sub Analysis_3()

'Change format for Total Percentage Change to Percent style
ws.Range("K" & SummaryTableTick2).Style = "Percent"
End If
End If


'Print the TotalStkVol to the Summary Table
ws.Range("L" & SummaryTableTick2).Value = TotalStkVol

'add one to the summary table row
SummaryTableTick2 = SummaryTableTick2 + 1

'reset the TotalStkVol back to zero
TotalStkVol = 0

'Else the tickers from one cell below to the cell above are equal, then continue
'to sum up the following:
Else
TotalOpenPrice = TotalOpenPrice + ws.Cells(Row, 3).Value
TotalClosePrice = TotalClosePrice + ws.Cells(Row, 6).Value
TotalStkVol = TotalStkVol + ws.Cells(Row, 7).Value

End If

Next Row

'set up SummaryTableGreatest
'Dim SummaryTableGreatest As Integer
'SummaryTableGreatest = 2

ws.Cells(1, 16).Value = "Ticker"
ws.Cells(1, 17).Value = "Value"
ws.Cells(2, 15).Value = "Greatest % Increase"
ws.Cells(3, 15).Value = "Greatest % Decrease"
ws.Cells(4, 15).Value = "Greatest Total Volume"

'define the max and min variables for the percent change
Dim Max As Double
Dim Min As Double

Max = Application.WorksheetFunction.Max(ws.Columns(11))
Min = Application.WorksheetFunction.Min(ws.Columns(11))


lastrowPercent = ws.Cells(Rows.Count, 11).End(xlUp).Row

'new loop for returning greatest % increase and decrease
'and total vol
For row2 = 2 To lastrowPercent

'set up max function for percentage change
If (ws.Cells(row2, 11).Value = Max) Then
ws.Cells(2, 16).Value = ws.Cells(row2, 9).Value
ws.Cells(2, 17).Value = Max
ws.Cells(2, 17).Style = "Percent"

'set up min function for percentage change
ElseIf (ws.Cells(row2, 11).Value = Min) Then
ws.Cells(3, 16).Value = ws.Cells(row2, 9).Value
ws.Cells(3, 17).Value = Min
ws.Cells(3, 17).Style = "Percent"

End If
Next row2


MaxTotalVol = Application.WorksheetFunction.Max(ws.Columns(12))
lastrowMaxVol = ws.Cells(Rows.Count, 12).End(xlUp).Row

'Start a new loop for TotalMaxVolume
For row3 = 2 To lastrowMaxVol

If (ws.Cells(row3, 12).Value = MaxTotalVol) Then
ws.Cells(4, 16).Value = ws.Cells(row3, 9).Value
ws.Cells(4, 17).Value = ws.Cells(row3, 12).Value
End If

Next row3

Next ws

End Sub
Binary file added images/VBA_2016_Stock_Mkt_Screenshot.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e123434

Please sign in to comment.