Calculate gallonage using VBA

zack8576

Active Member
Joined
Dec 27, 2021
Messages
271
Office Version
  1. 365
Platform
  1. Windows
I have this macro to calculate the gallonage of paint (CS55), it adds an additional row to the end of the excel file to display the gallonage
This part of the macro does the calculation. the "2" in the equation means two layers.
VBA Code:
.FormulaR1C1 = "=SUMIF(R2C11:R" & lr & "C11,""*CS55 Black*"",R2C3:R" & lr & "C3)"
        .Value = .Value * 0.000666 * 7.48 * 2

I need to modify the code so it can calculate the gallonage based on 1 layer or 2 layers.
1 layer (these all contain 1 letter B, which means black):
CS55 B/W
CS55 B/R/G (Black/red/gray)
CS55 B/G/R(Black/gray/red)

2 layers (these all contain 2 letter B):
CS55 B/W/B
CS55 B/R/B
CS55 B/G/B
CS55 Black (If it is a single color, then it is 2 layers)

full macro posted below for your reference

VBA Code:
Sub PaintCS55()
    Dim lrNew As Long
    lrNew = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
  
     With Range("C1", Cells(Rows.Count, "C").End(3))
        .Replace What:=" sqFt", Replacement:=vbNullString, LookAt:=xlPart
    End With
    lrNew = lrNew + 1                 
    Set c = ws1.Range("C" & lrNew)   
    With c
        .Offset(, -2).Value = .Offset(-1, -2).Value
        .FormulaR1C1 = "=SUMIF(R2C11:R" & lr & "C11,""*CS55 B*"",R2C3:R" & lr & "C3)"
        .Value = .Value * 0.000666 * 7.48 * 2
        .NumberFormat = "0"
        .Offset(, -1).Value = "."
        .Offset(, 1).Value = "F62655"
        .Offset(, 6).Value = "Purchased" 
        .Offset(, 8).Value = "CS55 Black"
'        .EntireRow.Font.Bold = True
    End With

    If Cells(lrNew, "C").Value Like 0 Then
        Rows(lrNew).Delete
    End If
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top