The script I've created performs the following tasks:
Loops through all stocks for a given year and outputs the following for each respective ticker category:
- Yearly change from the opening price to the closing price
- Percentage change from the opening price to the closing price
- Total stock volume
- Stock with the greatest percentage increase
- Stock with the greatest percentage decrease
- Stock with the greatest total volume This is a second tier of analysis using the analysis of each ticker category. Stock refers to each ticker category as a whole
- Implements conditional formatting to highlight positive change in green and negative change in red
- Script is applied across all sheets within the workbook
The StockAnalysis subroutine is designed to analyze stock market data contained within multiple sheets in an Excel workbook using VBA scripting. Here's how it works:
- This subroutine begins by declaring various variables, including integers for row numbers (outputRowNum, inputRowNum), a worksheet object (ws), string variables for ticker symbols (ticker, tickerPart), double variables for stock prices and volumes (openVal, closeVal, percentChange, totalStockVolume), and arrays to store the best-performing tickers and their corresponding values (allstarTickers, allstarValues).
- It then iterates through each worksheet in the workbook. Within the loop, it initializes variables and arrays, and sets header labels for the output data.
- During each iteration through the rows of the worksheet, it calculates the total stock volume for each ticker, determines the closing price, and prints the results including the yearly change, percentage change, and total stock volume. It also identifies the tickers with the greatest percentage increase, decrease, and total stock volume across all sheets.
- Finally, it prints the results for each worksheet, including the top-performing tickers, and adds percentage symbols to the percentage values.
Overall, this subroutine effectively analyzes stock market data in each worksheet, identifies top-performing stocks, and presents the results in the workbook.
- Download or clone this repository to your local machine.
- Open the Excel workbook containing the stock market data you want to analyze.
- Enable macros if prompted.
- Press Alt + F8 to open the "Run Macro" dialog.
- Select StockAnalysis() from the list and click Run. The script will run on each sheet of the workbook, analyzing the data and displaying the results accordingly.
- StockAnalysis().bas: The VBA script responsible for analyzing the stock market data.
- README.md: You're reading it right now! Provides information about the project.
- Images of 2018 - 2020 Multiple Stock Year Data Results of Sample Data provided in UCB Data Analytics Bootcamp
Make sure to save your Excel workbook before running the script to avoid any data loss. For any issues or suggestions, feel free to create an issue or submit a pull request.
Further, please make sure data is in columns A-G in this order: