-
Notifications
You must be signed in to change notification settings - Fork 0
/
Easy Script.txt
61 lines (40 loc) · 1.84 KB
/
Easy Script.txt
1
Sub easy_test() ' Set for each worksheet For Each ws In Worksheets 'Set last row LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row ' Set an initial variable for holding the ticker name Dim Stock_Name As String ' Set an initial variable for holding the total volume per stock name Dim Stock_Total As Double Stock_Total = 0 ' Keep track of the location for each stock name in the summary table Dim Summary_Table_Row As Integer Summary_Table_Row = 2 ' Loop through all stocks For i = 2 To LastRow ' Check if we are still within the same stock name, if not then.. If ws.Cells(i + 1, 1).Value <> ws.Cells(i, 1).Value Then ' Set the stock name Stock_Name = ws.Cells(i, 1).Value 'Add to the stock total Stock_Total = Stock_Total + ws.Cells(i, 7).Value ' Print the Stock Name in the Summary Table ws.Range("I" & Summary_Table_Row).Value = Stock_Name ' Print the Volume total per stock ws.Range("J" & Summary_Table_Row).Value = Stock_Total ' Add one to the summary table row Summary_Table_Row = Summary_Table_Row + 1 ' Reset the Stock Total Stock_Total = 0 ' If the cell immediately following a row is the same stock... Else 'Add to the Stock Total Stock_Total = Stock_Total + ws.Cells(i, 7).Value End If Next i 'Print the headers for Table ws.Cells(1, 9).Value = "Ticker" ws.Cells(1, 10).Value = "Total Stock Volume" Next ws End Sub