I have this code that counts the number of "CHAIN & EYEBOLT" in some excel files, then adds one row at the end of the file to show the total number of this item.
The new row should always have: column A (value from cell above), C (total number of the item), B, D, I and K with the static values shown below
This code works............on 90% of the files, but on a few test files, it is not copying the value in column A, like the example below, cell A returned as blank
I am not sure exactly what is causing this issue, any help is appreciated
dropbox link below for 2 test files, this one is working
and this one is not
full code below, any criticism on the way this is coded is also welcome.
I am always looking for ways to improve these VBA codes..
The new row should always have: column A (value from cell above), C (total number of the item), B, D, I and K with the static values shown below
This code works............on 90% of the files, but on a few test files, it is not copying the value in column A, like the example below, cell A returned as blank
I am not sure exactly what is causing this issue, any help is appreciated
dropbox link below for 2 test files, this one is working
and this one is not
full code below, any criticism on the way this is coded is also welcome.
I am always looking for ways to improve these VBA codes..
VBA Code:
Sub EyeboltsAndChains()
Dim lrNew As Long
lrNew = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
sr = 2
With Range("M1", Cells(Rows.Count, "M").End(3))
.Replace What:="@ 18""", Replacement:=vbNullString, LookAt:=xlPart
.Replace What:="@ 24""", Replacement:=vbNullString, LookAt:=xlPart
.Replace What:="@ 30""", Replacement:=vbNullString, LookAt:=xlPart
.Replace What:="@ 42""", Replacement:=vbNullString, LookAt:=xlPart
.Replace What:="@ 48""", Replacement:=vbNullString, LookAt:=xlPart
.Replace What:="@ 60""", Replacement:=vbNullString, LookAt:=xlPart
.Replace What:="@ 72""", Replacement:=vbNullString, LookAt:=xlPart
.Replace What:="&", Replacement:=vbNullString, LookAt:=xlPart
.Replace What:="2 1", Replacement:="3", LookAt:=xlPart
End With
n = WorksheetFunction.SumIfs(Range("M" & sr & ":M" & lr), Range("K" & sr & ":K" & lr), "*CHAIN & EYEBOLT*")
lrNew = lrNew + 1
Cells(lrNew, "A") = Cells(lr, "A")
Cells(lrNew, "B") = "."
Cells(lrNew, "C") = n
Cells(lrNew, "D") = "F09720"
Cells(lrNew, "I") = "Purchased"
Cells(lrNew, "K") = "CHAIN & EYEBOLT"
If Cells(lrNew, "C").Value Like "*0*" Then
Rows(lrNew).Delete
End If
End Sub