Sum all rows containing text string VBA

orsm6

Active Member
Joined
Oct 3, 2012
Messages
496
Office Version
  1. 365
Platform
  1. Windows
Hi guru's again i need some expert help....... with code i am trying to sum the contents of column O (beginning from O3) but to only sum it if column E = Z004, Z003, Z002 and CONV.

the hard part of this is.... the sum total needs to also go in column O, the sum total will not always be in the same row as the report size can change....what remains constant though is the sum total will ALWAYS be 5 columns to the right of a cell containing "total raw and pack cost"

i hope the table helps.

COGs runner.xlsm
EIJKLMNOPQRSTUV
1Total Manufactured CostCosting BoM (with Loss)
2Material TypeResourceResource TextQuantityBase UoMPriceBase UnitZero BoMComponent Scrap (%)Operating Scrap (%)Op. Scrap (Y/N) + Component Scrap + Operating ScrapQuantityCosting BoM
3Z004200320281010.1EA$301.001000$304.041.012030.301$611.12
4Z004200317086060.6EA$83.821000$508.001.0112181.806$1,021.08
5Z004200317096060.6EA$47.251000$286.361.0112181.806$575.59
6Z004PA0217002040.8EA$7.551000$15.412.046204.032$46.84
7Z004PA02759610.677EA$530.401000$5.662.537.3695$19.82
8Z004PA0297516122.4EA$16.431000$100.592.0418612.096$305.80
9Z003RA001003-1.506KG$2,530.001000-$3.81000-1.506-$3.81
10Z003RA0010031.506KG$2,530.001000$3.810001.506$3.81
11Z003RA001965382.6KG$3,026.661000$1,158.001.6612.160994.76$3,010.80
12Z002SA000450563.185KG$3,987.051000$2,245.4513.717721.2663508284.45135$33,030.52
13Z003RA001003-1.13KG$2,530.001000-$2.86000-1.13-$2.86
14Z003RA0010031.13KG$2,530.001000$2.860001.13$2.86
15Z003RA0010110.836KG$13,650.001000$11.4111.9810.01528010.85128$148.12
16Z003RA00103034.196KG$4,407.001000$150.7012.57429.843720464.03972$2,045.02
17Z003RA0012561.259KG$32,499.341000$40.9212.1215.25908016.51808$536.83
18Z003RA0012602.514KG$2,450.001000$6.1611.9830.11772032.63172$79.95
19Z003RA0016727.064KG$397.801000$2.8112.689.0064096.0704$38.22
20Z002SA0012121326.33KG$1,468.241000$1,947.370.72954.957602281.2876$3,349.48
21Total Raw & Pack Cost$6,782.88
22
30CONVDVL18.381HR$5,537.87100$464.130$464.13
31CONVFIX11500KG$1,013.2510000$151.990$151.99
32CONVFMHR10.92HR$1,940.6110$178.540$178.54
33CONVDVE11500KG$283.4110000$42.510$42.51
34Total Conversion Cost$995.49
35Costing BoM
36Total Manufactured Cost$7,778.37
Layout
Cells with Conditional Formatting
CellConditionCell FormatStop If True
K3:K100Expression=$K3="Unit Price"textNO
Q3:T100Expression=$E3="Z004"textNO
K3:K100Expression=$K3="Conversion"textNO
K3:K100Expression=$K3="Raw"textNO
K3:K100Expression=$K3="pack"textNO
V3:V100,A3:P100Expression=$E3="CONV"textNO
A3:V100Expression=$E3="Z002"textNO
A3:V100Expression=$E3="Z003"textNO
A3:V100Expression=$E3="Z004"textNO
A3:V100Cell Valuecontains "BoM"textNO
A3:V100Cell Valuecontains "Total"textNO
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
How about:

Dante Amor
EIJKLMNOP
1Total Manufactured CostCosting BoM (with Loss)
2Material TypeResourceResource TextQuantityBase UoMPriceBase UnitZero BoMComponent Scrap (%)
3Z004200320281010.1EA3011000304.04011.01
4Z004200317086060.6EA83.821000507.9994921.01
5Z004200317096060.6EA47.251000286.363351.01
6Z004PA0217002040.8EA7.55100015.408042.04
7Z004PA02759610.677EA530.410005.66308082.5
8Z004PA0297516122.4EA16.431000100.5910322.04
9Z003RA001003-1.506KG25301000-3.810180
10Z003RA0010031.506KG253010003.810180
11Z003RA001965382.6KG3026.6610001158.000121.6
12Z003SA000450563.185KG3987.0510002245.4467513.71
13Z003RA001003-1.13KG25301000-2.85890
14Z003RA0010031.13KG253010002.85890
15Z003RA0010110.836KG13650100011.411411.98
16Z003RA00103034.196KG44071000150.70177212.57
17Z003RA0012561.259KG32499.34100040.916669112.12
18Z003RA0012602.514KG245010006.159311.98
19Z003RA0016727.064KG397.810002.810059212.6
20Z002SA0012121326.33KG1468.2410001947.370760.72
21Total Raw & Pack Cost6782.88192
s1
Cell Formulas
RangeFormula
O21O21=SUM(SUMIFS($O$3:INDEX($O$3:$O$1000,MATCH("Total Raw & Pack Cost",$J$3:$J$1000,0)-1),$E$3:INDEX($E$3:$E$1000,MATCH("Total Raw & Pack Cost",$J$3:$J$1000,0)-1),{"Z002","Z003","Z004","CONV"}))
 
Upvote 0
Try this
VBA Code:
Sub sum_rows()
  Dim f As Range
  Set f = Range("J:J").Find("Total Raw & Pack Cost", , xlValues, xlWhole)
  If Not f Is Nothing Then
    f.Offset(, 5).Value = Evaluate("=SUM(SUMIFS(O3:O" & f.Row - 1 & ",E3:E" & f.Row - 1 & ",{""Z002"",""Z003"",""Z004"",""CONV""}))")
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,485
Messages
6,113,931
Members
448,533
Latest member
thietbibeboiwasaco

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