already solved it
Sub CheckInstandCol()
For Z = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
If Cells(Z, "H").Value = "MLY" And Cells(Z, "I").Value = "MLY" Then
mycell = Cells(Z, "A").Value
myOcc = Application.CountIf(Range("A1", Cells(Rows.Count, "A").End(xlUp)), mycell)
myNumofOC = myOcc - 1
Cells(Z, "B").Value = myNumofOC
myOrderNr = Cells(Z, "A").Value
myPrelCost = Cells(Z, "AB").Value
myResult = myPrelCost / myNumofOC
Cells(Z, "B").Value = myNumofOC
Cells(Z, "B").EntireRow.Interior.ColorIndex = 4
End If
Next Z
For X = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
If Cells(X, "H").Value = "IND" And Cells(X, "I").Value = "IND" Then
mycell = Cells(X, "A").Value
myOcc = Application.CountIf(Range("A1", Cells(Rows.Count, "A").End(xlUp)), mycell)
myNumofOC = myOcc - 1
Cells(X, "B").Value = myNumofOC
myOrderNr = Cells(X, "A").Value
myPrelCost = Cells(X, "AB").Value
myResult = myPrelCost / myNumofOC
Cells(X, "B").Value = myNumofOC
Cells(X, "B").EntireRow.Interior.ColorIndex = 6
End If
Next X
End Sub
Sub CheckNumOfIns()
For Z = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
If Cells(Z, "H").Value = "MLY" And Cells(Z, "I").Value = "MLY" Then
mycell = Cells(Z, "A").Value
myOcc = Application.CountIf(Range("A1", Cells(Rows.Count, "A").End(xlUp)), mycell)
myNumofOC = myOcc - 1
Cells(Z, "B").Value = myNumofOC
myOrderNr = Cells(Z, "A").Value
myPrelCost = Cells(Z, "AB").Value
myResult = myPrelCost / myNumofOC
Cells(Z, "B").Value = myNumofOC
End If
Next Z
For i = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
If Cells(i, "b").Value > 0 Then
mycell = Cells(i, "A").Value
myVal = Cells(i, "B").Value
myPrel = Cells(i, "AB").Value
mySum = Val(myPrel / myVal)
End If
For X = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
If Cells(X, "A").Value = mycell Then
Cells(X, "R").Value = mySum
End If
Next X
Next i
End Sub