Sub Extract_data_for_Friedman_Test()
Dim year As Integer, avg As Double, mos As Integer, group As Integer, irow As Long, irow2 As Integer, icol2 As Integer
Dim count As Long
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.DisplayStatusBar = True
count = 0
For irow = 2 To 501434
year = Cells(irow, 1)
avg = Cells(irow, 2)
mos = Cells(irow, 3)
group = Cells(irow, 4)
For icol = 6 To 2678 Step 8
If Cells(1, icol) = group Then
For irow2 = 2 To 139
If Cells(irow2, icol) = mos Then
For icol2 = icol + 1 To icol + 7
If Cells(1, icol2) = year Then
count = count + 1
Cells(irow2, icol2) = avg
Application.StatusBar = "Iteration = " & count
DoEvents
GoTo 10
End If
Next icol2
End If
Next irow2
End If
Next icol
10 Next irow
End Sub