With ThisWorkbook.Worksheets("StockControl") Range("h:h").ClearContents Range("i:i").ClearContents Cells(1, 8) = "Backorder Qty" Cells(1, 9) = "StockControl" A = Range(Cells(2, 1), Cells(2, 1).End(xlDown)).Rows.Count ' satır sayısı For i = 1 To A reqdate = Cells(i + 1, 2) sku = Cells(i + 1, 1) If Cells(i + 1, 1) <> Cells(i, 1) Then k = i End If openord = 0 For j = k To A If Cells(j + 1, 1) = sku And Cells(j + 1, 2) <= reqdate And Cells(j + 1, 3) >= reqdate Then openord = Cells(j + 1, 4) + openord End If If Cells(j + 2, 1) <> Cells(j + 1, 1) Then Exit For End If Next Cells(i + 1, 8) = openord If Cells(i + 1, 5) < Cells(i + 1, 8) * 0.97 Then Cells(i + 1, 9) = 0 Else Cells(i + 1, 9) = 1 End If Next End With