Another solution
Sub abc()
Dim arrOut, i As Long, ii As Long, iii As Long
With Worksheets("SQL export")
ReDim arrOut(1 To (.Cells(Rows.Count, "a").End(xlUp).Row - 1) * 7, 1 To 5)
For i = 2 To .Cells(Rows.Count, "a").End(xlUp).Row
For ii = 1 To 7
iii = iii + 1
arrOut(iii, 1) = .Cells(i, 1) & ii
arrOut(iii, 2) = .Cells(i, 1)
arrOut(iii, 3) = ii
arrOut(iii, 4) = VBA.Format(.Cells(i, 1 + ii) / 60 / 24, "h:mm AM/PM")
arrOut(iii, 5) = VBA.Format(.Cells(i, 8 + ii) / 60 / 24, "h:mm AM/PM")
Next
Next
End With
With Worksheets("Desired output")
.Cells(1).Resize(, 6) = Array("Concatenate", "Expr2", "Weekday", "Open", "Close", "BDH [?]")
.Cells(2, 1).Resize(UBound(arrOut), 5) = arrOut
With .Cells(2, 6).Resize(UBound(arrOut))
.Formula = "=IF(C2<6,IF(D2>AVERAGEIFS(D:D,B:B,B2,C:C,""<6""),""BDH"",""""),"""")"
.Value = .Value
End With
.Cells.EntireColumn.AutoFit
End With
End Sub
Bookmarks