Q:

Excel VBA multiple loops based on columns

Excel Screenshot
I have a lots of price data but want to analyse it in terms or a hourly price divided by a weekly average (week being Sunday to Sunday) for a few years. 
Basically in 'column L' i'm trying to get a coefficient (hourly price divided by weekly average) were the average has been separated into peak hours (between 0800 and 2100) and off peak hours (all other hours) - an average for peak and an average for off peak. 
Here is my code but i'm really new to VBA and this is not right, not sure how to fix it:
Sub averagehourprice()
Dim MyRange As Range
Dim t As Integer
Dim x As Integer
Dim y As Integer

For t = 2012 To 2016 'for each year loop
Range ("B2:B43135")

    For x = 1 To 52 'for each week loop
    Range ("D2:D43135")

        For y = 1 To 24 'for each hour in each week loop
        Range ("F2:F43135")

        'create a coulmn of peak hours and off peak hours
        If Range("F2:F43135") > 8 And Range("F2:F43135") < 21 Then Range("H2:H43135") = 1
        'if each cell value in the range is "F2:F43135" >8 and < than 21 then coresspondinbg cell in H =1 else 0
        Else: Range "H2:H43135" = "-"
        End If
        'if a cell in H is "-" then cell in I = 1
        If Range("H2:H43135") = "-" Then Range("I2:I43135") = 1
        Else: Range("I2:I43135") = "-"
        End If

        'get weekly average of peak values and weekly average of off peak values
        Range("J2:J43135") = Sum((Range("G2:G43135")) * (Range("H2:H43135"))) / Sum((Range("H2:H43135")))
        Range("K2:K43135") = Sum((Range("G2:G43135")) * (Range("I2:I43135"))) / Sum((Range("I2:I43135")))

        'create a coeffieicent as a function of day price and average weekly price

        Range("L2:L43135") = Range("G2:G43135") / Range("J2:J43135") + Range("G2:G43135") / Range("K2:K43135")

        Next y
    Next x
Next t

End Sub

Many thanks for your help in advance. 

A:

I think you don't understand completely how to  use loops.  The purpose of a loop is that you have a variable that needs to be used in a function.  You specify a variable but you don't use it.  See this link for more information: http://www.excel-easy.com/vba/loop.html
what you exactly want to do with the loop is not totaly clear to me.  Maybe if you can explain your question a little bit more extensively for me I can create something for you to work with
PS: This should be in the comment and not as Answer, but I don't have enough rep to comment 
I have the following for you.  The macro beneath will give you the average price per week for each year.  If you lable column I as 2012, J as 2013...... then in this column will appear for week 1 to 52 the average price in that week.  
paste this in a module and change the sheetname, then run it:
Sub averageperweek()

For i = 2 To 43145
If Sheets("sheet1").Range("B" & i).Value = "2012" Then Column = 9
If Sheets("sheet1").Range("B" & i).Value = "2013" Then Column = 10
If Sheets("sheet1").Range("B" & i).Value = "2014" Then Column = 11
If Sheets("sheet1").Range("B" & i).Value = "2015" Then Column = 12
If Sheets("sheet1").Range("B" & i).Value = "2016" Then Column = 13

Row = Sheets("sheet1").Range("D" & i).Value + 1

Sheets("sheet1").Cells(Row, Column).Value = (Sheets("sheet1").Cells(Row, Column).Value + Sheets("sheet1").Range("G" & i).Value) / 168

Next i

End Sub

Looking at your screenshot, it appears that your week numbers are not correct.  At 2 jan your week number also goes to 2. 
hope this will help you, and if you need more help don't hesitate to ask

