I know I haven't answered your question about summing a variable range, but see if this does what you want. Test in a
copy of your workbook. Check that In have data in correct rows/columns or a slight tweak will be needed.
Excel Workbook |
---|
|
---|
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R |
---|
3 | ID | Items | BAR DIA | SHAPE | SEQ NO. | BAR GRADE | BAR DIMENSIONS | | | | | PIN DIA (P) | LAPS | | | NO | BAR LENGTH | TOTAL MASS |
---|
4 | | | | | | | A | B | C | E | F | | L | NO | TYPE | REQ | | |
---|
5 | 1 | A | 12 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
---|
6 | 1 | A | 12 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
---|
7 | 1 | A | 40 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
---|
8 | 1 | A | 40 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
---|
9 | 2 | B | 12 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
---|
10 | 2 | B | 12 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
---|
11 | 2 | B | 16 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
---|
12 | 2 | B | 40 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
---|
13 | 3 | C | 40 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
---|
14 | 3 | C | 40 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
---|
15 | 3 | C | 40 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
---|
16 | 3 | C | 40 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
---|
17 | | | | | | | | | | | | | | | | | | |
---|
|
---|
Excel Workbook |
---|
|
---|
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R |
---|
3 | ID | Items | BAR DIA | SHAPE | SEQ NO. | BAR GRADE | BAR DIMENSIONS | | | | | PIN DIA (P) | LAPS | | | NO | BAR LENGTH | TOTAL MASS |
---|
4 | | | | | | | A | B | C | E | F | | L | NO | TYPE | REQ | | |
---|
5 | 1 | A | 12 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
---|
6 | 1 | A | 12 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
---|
7 | 1 | A | 40 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
---|
8 | 1 | A | 40 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
---|
9 | Sub-Total | 4 | @ Dia 12 | 2 | @ Dia 16 | 0 | @ Dia 20 | 0 | @ Dia 24 | 0 | @ Dia 28 | 0 | @ Dia 32 | 0 | @ Dia 36 | 0 | @ Dia 40 | 2 |
---|
10 | 2 | B | 12 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
---|
11 | 2 | B | 12 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
---|
12 | 2 | B | 16 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
---|
13 | 2 | B | 40 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
---|
14 | Sub-Total | 8 | @ Dia 12 | 4 | @ Dia 16 | 2 | @ Dia 20 | 0 | @ Dia 24 | 0 | @ Dia 28 | 0 | @ Dia 32 | 0 | @ Dia 36 | 0 | @ Dia 40 | 2 |
---|
15 | 3 | C | 40 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
---|
16 | 3 | C | 40 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
---|
17 | 3 | C | 40 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
---|
18 | 3 | C | 40 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
---|
19 | Sub-Total | 12 | @ Dia 12 | 0 | @ Dia 16 | 0 | @ Dia 20 | 0 | @ Dia 24 | 0 | @ Dia 28 | 0 | @ Dia 32 | 0 | @ Dia 36 | 0 | @ Dia 40 | 12 |
---|
20 | | | | | | | | | | | | | | | | | | |
---|
|
---|
<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> STot()<br> <SPAN style="color:#00007F">Dim</SPAN> a, st, strw, t<br> <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, lr <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, c <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br> <br> st = Array("Sub-Total", 1, "@ Dia 12", 12, "@ Dia 16", 16, _<br> "@ Dia 20", 20, "@ Dia 24", 24, "@ Dia 28", 28, _<br> "@ Dia 32", 32, "@ Dia 36", 36, "@ Dia 40", 40)<br> <br> Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br> <SPAN style="color:#00007F">ReDim</SPAN> t(1 <SPAN style="color:#00007F">To</SPAN> 40) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br> <SPAN style="color:#00007F">With</SPAN> Range("A4", Range("A" & Rows.Count).End(xlUp)).Resize(, 18)<br> Application.DisplayAlerts = <SPAN style="color:#00007F">False</SPAN><br> .Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(2), _<br> Replace:=True, PageBreaks:=False, SummaryBelowData:=<SPAN style="color:#00007F">True</SPAN><br> Application.DisplayAlerts = <SPAN style="color:#00007F">True</SPAN><br> lr = Range("A" & Rows.Count).End(xlUp).Row - 1<br> a = .Offset(-.Row + 1).Resize(lr).Value<br> i = .Row<br> <SPAN style="color:#00007F">Do</SPAN><br> i = i + 1<br> <SPAN style="color:#00007F">If</SPAN> a(i, 3) = "" <SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">ReDim</SPAN> strw(LBound(st) <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(st))<br> <SPAN style="color:#00007F">For</SPAN> c = <SPAN style="color:#00007F">LBound</SPAN>(st) <SPAN style="color:#00007F">To</SPAN> <SPAN style="color:#00007F">UBound</SPAN>(st)<br> <SPAN style="color:#00007F">If</SPAN> IsNumeric(st(c)) <SPAN style="color:#00007F">Then</SPAN><br> strw(c) = t(st(c))<br> <SPAN style="color:#00007F">Else</SPAN><br> strw(c) = st(c)<br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> c<br> <SPAN style="color:#00007F">ReDim</SPAN> t(1 <SPAN style="color:#00007F">To</SPAN> 40) <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br> <SPAN style="color:#00007F">With</SPAN> Cells(i, 1).Resize(, 18)<br> .Font.Bold = <SPAN style="color:#00007F">False</SPAN><br> .RowHeight = 25<br> .Value = strw<br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br> <SPAN style="color:#00007F">Else</SPAN><br> t(a(i, 3)) = t(a(i, 3)) + a(i, 18)<br> t(1) = t(1) + a(i, 18)<br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Loop</SPAN> <SPAN style="color:#00007F">While</SPAN> i < lr<br> .EntireColumn.AutoFit<br> .Resize(lr).RemoveSubtotal<br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br> Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
I hope that is at least close to what you are after.