part of my macro is to do a tabulation of a certain item when column K contains keywords "9"" and Wrapid-Seal", counts the total qty
if K does not contain the keywords then qty = 0
every time I run this macro, qty is always zero, even know the excel file indeed have this item in K. Why is that?
Code below, test file link below, any help is appreciated !
if K does not contain the keywords then qty = 0
every time I run this macro, qty is always zero, even know the excel file indeed have this item in K. Why is that?
Code below, test file link below, any help is appreciated !
VBA Code:
Sub WrapidSealSmall()
Dim lrNew As Long, i As Long
lrNew = ActiveSheet.Range("K" & Rows.Count).End(xlUp).Row
sr = 2
For i = 2 To lastRow
If Range("K" & i).Value Like "*9*" And _
Range("K" & i).Value Like "*Wrapid-Seal*" Then
n = Application.Sum(Application.SumIfs(Range("C" & sr & ":C" & lr), Range("K" & sr & ":K" & lr), _
Array("*Base*", "*Riser*", "*Cone*", "*Top Slab*"), Range("O" & sr & ":O" & lr), "*SANITARY*"))
Else
n = 0
End If
Next i
With Columns("A:K")
lrNew = lrNew + 1
.Rows(lrNew) = Array(Cells(lr, "A"), ".", n - 1, "F25888A", "No", """", """", """", "Purchased", """", "9"" Closure")
If Cells(lrNew, "C").Value = 0 Or _
Cells(lrNew, "C").Value < 0 Then
Cells(lrNew, 4) = ","
End If
lrNew = lrNew + 1
.Rows(lrNew) = Array(Cells(lr, "A"), ".", (n - 1) / 8, "F25889A", "No", """", """", """", "Purchased", """", "Primer")
If Cells(lrNew, "C").Value = 0 Or _
Cells(lrNew, "C").Value < 0 Then
Rows(lrNew).Delete
End If
lrNew = lrNew + 1
.Rows(lrNew) = Array(Cells(lr, "A"), ".", """", "F51040", "No", """", """", """", "Purchased", """", "9"" Wrapid-Seal")
If n = 0 Then
Rows(lrNew).Delete
End If
End With
End Sub