Sub CalculateVolumeRatios()
' Set variables for sheet and starting/ending row numbers
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")
Dim startRow As Long, endRow As Long
startRow = 2 ' Assuming header row in row 1, change if necessary
endRow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row
' Iterate through rows and calculate ratios for each row
Dim i As Long
For i = startRow To endRow
' Get last volume (column E)
Dim lastVolume As Double
lastVolume = ws.Cells(i, "E").Value
' Calculate week average and ratio (column J)
Dim weekAvg As Double
weekAvg = Application.WorksheetFunction.Average(ws.Range(ws.Cells(i - 4, "E"), ws.Cells(i, "E")))
ws.Cells(i, "J").Value = lastVolume / weekAvg
' Calculate month average and ratio (column K)
Dim monthAvg As Double
monthAvg = Application.WorksheetFunction.Average(ws.Range(ws.Cells(i - 19, "E"), ws.Cells(i, "E")))
ws.Cells(i, "K").Value = lastVolume / monthAvg
' Calculate 3 month average and ratio (column L)
Dim threeMonthAvg As Double
threeMonthAvg = Application.WorksheetFunction.Average(ws.Range(ws.Cells(i - 59, "E"), ws.Cells(i, "E")))
ws.Cells(i, "L").Value = lastVolume / threeMonthAvg
Next i
End Sub
This code assumes that the volume data is in column E, starting with row 2, and you want the calculated ratios to be in columns J, K, and L. The code calculates the ratios for every row, but you can adjust the startRow and endRow variables as needed. The code also assumes that a week has 5 trading days, a month has 20 trading days, and 3 months have 60 trading days, but you can adjust those numbers in the ws.Range functions if necessary.