I need to calculate the total inches of item "Evergrip" in some excel files, then apply a simple equation to convert this number into rolls.
In my code, I would remove the inch mark and the text "/JOINT" from column M, count the total inches, then take this value divide by 12 then divide by 14.5 to get the number of rolls.
Then a new row is added after the last row that contains any value, the number of rolls along with few other values will be added to this new row.
If the number of rolls is 0, then the value in column D on this row gets replaced by a comma.
code below, test file attached, the result from the calculation looks wrong, so there is a mistake in the code. any help is greatly appreciated
In my code, I would remove the inch mark and the text "/JOINT" from column M, count the total inches, then take this value divide by 12 then divide by 14.5 to get the number of rolls.
Then a new row is added after the last row that contains any value, the number of rolls along with few other values will be added to this new row.
If the number of rolls is 0, then the value in column D on this row gets replaced by a comma.
code below, test file attached, the result from the calculation looks wrong, so there is a mistake in the code. any help is greatly appreciated
VBA Code:
Public sr As Long, lr11 As Long, lr10 As Long, rng2 As Range, n As Long
Sub Sealant()
sr = 2 'Starting Row
Set rng2 = Range("A1").CurrentRegion
lr11 = rng2.Cells(Rows.Count, "M").End(3).Row
If rng2.Cells(lr4, "M").Value Like "/JOINT" Then
With Range("M1", Cells(Rows.Count, "M").End(3))
.Replace What:="""", Replacement:=vbNullString, LookAt:=xlPart 'REMOVE THE INCH MARK
.Replace What:="/JOINT", Replacement:=vbNullString, LookAt:=xlPart ' REMOVE /JOINT
End With
End If
n = WorksheetFunction.SumIfs(Range("M" & sr & ":M" & lr), Range("K" & sr & ":K" & lr), "*Evergrip*") 'COUNT THE TOTAL NUMBER IN M, IF COLUMN K CONTAINS THE KEYWORD JOINT SEALANT.
lr10 = lr6 + 1
Cells(lr10, "A") = Cells(lr, "A")
Cells(lr10, "B") = "."
Cells(lr10, "C") = n / 12 / 14.5
Cells(lr10, "D") = "F09510A"
Cells(lr10, "I") = "Purchased"
Cells(lr10, "K") = "Evergrip"
'IF COLUMN C IN THE NEW ROW IS 0, VALUE IN D GETS REPLACED BY ,
If Cells(lr10, "C").Value Like "*0*" Then
Cells(lr10, 4) = ","
End If
End Sub