I need my macro to calculate the quantity of item "evergrip", the calculation goes like the following:
It calculates the total number of "Base", "Riser", "Cone", "Top slab" with the keyword "Sanitary" in column O.
the qty of these items are always in column C, the description of these items are in column K.
the macro then run this equation: (total # of these items - 1) * 14 and display the qty on a new row that is added after the last row with any data
see my code below, it looks like this is not counting the items correctly, my result always returns as -14
test file link below
It calculates the total number of "Base", "Riser", "Cone", "Top slab" with the keyword "Sanitary" in column O.
the qty of these items are always in column C, the description of these items are in column K.
the macro then run this equation: (total # of these items - 1) * 14 and display the qty on a new row that is added after the last row with any data
see my code below, it looks like this is not counting the items correctly, my result always returns as -14
test file link below
VBA Code:
Public sr As Long, n As Long, lr10 As Long, lr As Long, lr6 As Long
Sub SealantEvergrip()
lr = ws1.Cells(Rows.Count, "K").End(xlUp).Row
sr = 2 'Starting Row
n = WorksheetFunction.SumIfs(Range("C" & sr & ":C" & lr), Range("K" & sr & ":K" & lr), "*Base**Riser**Cone**Top Slab*", Range("O" & sr & ":O" & lr), "*Sanitary*")
lr10 = lr6 + 1 'this is the new row at the bottom that we are going to write the data to.
Cells(lr10, "A") = Cells(lr, "A")
Cells(lr10, "B") = "."
Cells(lr10, "C") = (n - 1) * 14
Cells(lr10, "D") = "F09510A"
Cells(lr10, "I") = "Purchased"
Cells(lr10, "K") = "Evergrip"
If Cells(lr10, "C").Value Like "*0*" Then
Cells(lr10, 4) = ","
End If
End Sub