jardenp
Active Member
- Joined
- May 12, 2009
- Messages
- 373
- Office Version
- 2019
- 2016
- 2013
- 2011
- 2010
- Platform
- Windows
I need a VBA formula to enter in a cell in a certain row (row # = WeeklyTotalsAddRow variable) in the column with the header "Total" in row 1 that will give me the sum of all the cells to the left of this cell except columns A-C.
The column with the "Total" header could be anywhere from column G through BA.
I write to the cell with this:
In this example, WeeklyTotalsAddRow is equal to 5, so the code would write "=SUM(D5:F5)" in G5 and result in "6" (previous rows already have sum formulas in Total column):
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Set[/TD]
[TD]Co.[/TD]
[TD]Sale1[/TD]
[TD]Sale2[/TD]
[TD]Sale3[/TD]
[TD]Total[/TD]
[/TR]
[TR]
[TD]Joe[/TD]
[TD]X4[/TD]
[TD]456[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]=SUM(D1:F1)[/TD]
[/TR]
[TR]
[TD]Jim[/TD]
[TD]X5[/TD]
[TD]789[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]=SUM(D2:F2)[/TD]
[/TR]
[TR]
[TD]Jill[/TD]
[TD]X6[/TD]
[TD]101[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]=SUM(D3:F3)[/TD]
[/TR]
[TR]
[TD]Jess[/TD]
[TD]X7[/TD]
[TD]112[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Here it would write "=SUM(D5:G5)" in H5 and result in "8":
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Set[/TD]
[TD]Co.[/TD]
[TD]Sale1[/TD]
[TD]Sale2[/TD]
[TD]Sale3[/TD]
[TD]Sale4[/TD]
[TD]Total[/TD]
[/TR]
[TR]
[TD]Joe[/TD]
[TD]X4[/TD]
[TD]456[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]=SUM(D1:G1)[/TD]
[/TR]
[TR]
[TD]Jim[/TD]
[TD]X5[/TD]
[TD]789[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]=SUM(D2:G2)[/TD]
[/TR]
[TR]
[TD]Jill[/TD]
[TD]X6[/TD]
[TD]101[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]=SUM(D3:G3)[/TD]
[/TR]
[TR]
[TD]Jess[/TD]
[TD]X7[/TD]
[TD]112[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I can figure out how to select the cell above it and autofill down, but the formula in Total may or may not be a straight SUM like I want, so that's not reliable.
Thanks!
Josh in IN
The column with the "Total" header could be anywhere from column G through BA.
I write to the cell with this:
Code:
Cells(WeeklyTotalsAddRow, Application.WorksheetFunction.Match("Total", Range("A1:BA1"), 0)).Formula = [U][B]???[/B][/U]
In this example, WeeklyTotalsAddRow is equal to 5, so the code would write "=SUM(D5:F5)" in G5 and result in "6" (previous rows already have sum formulas in Total column):
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Set[/TD]
[TD]Co.[/TD]
[TD]Sale1[/TD]
[TD]Sale2[/TD]
[TD]Sale3[/TD]
[TD]Total[/TD]
[/TR]
[TR]
[TD]Joe[/TD]
[TD]X4[/TD]
[TD]456[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]=SUM(D1:F1)[/TD]
[/TR]
[TR]
[TD]Jim[/TD]
[TD]X5[/TD]
[TD]789[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]=SUM(D2:F2)[/TD]
[/TR]
[TR]
[TD]Jill[/TD]
[TD]X6[/TD]
[TD]101[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]=SUM(D3:F3)[/TD]
[/TR]
[TR]
[TD]Jess[/TD]
[TD]X7[/TD]
[TD]112[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Here it would write "=SUM(D5:G5)" in H5 and result in "8":
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Set[/TD]
[TD]Co.[/TD]
[TD]Sale1[/TD]
[TD]Sale2[/TD]
[TD]Sale3[/TD]
[TD]Sale4[/TD]
[TD]Total[/TD]
[/TR]
[TR]
[TD]Joe[/TD]
[TD]X4[/TD]
[TD]456[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]=SUM(D1:G1)[/TD]
[/TR]
[TR]
[TD]Jim[/TD]
[TD]X5[/TD]
[TD]789[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]=SUM(D2:G2)[/TD]
[/TR]
[TR]
[TD]Jill[/TD]
[TD]X6[/TD]
[TD]101[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]3[/TD]
[TD]=SUM(D3:G3)[/TD]
[/TR]
[TR]
[TD]Jess[/TD]
[TD]X7[/TD]
[TD]112[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I can figure out how to select the cell above it and autofill down, but the formula in Total may or may not be a straight SUM like I want, so that's not reliable.
Thanks!
Josh in IN