# Thread: Macro to Sum Cells in Two Columns Thanks: 0 Likes: 0

1. ## Macro to Sum Cells in Two Columns

Hi All,

I have a monthly spreadsheet that data will be in different columns. I want to sum the cells in two columns based on finding the header (which will always be the same text) and put the summed total in another column at the end of the spreadsheet. Can anyone help me with this please?

2. ## Re: Macro to Sum Cells in Two Columns

Show us an example of your data and the expected solution. Be more specific in your explanation using your sample data for reference.

3. ## Re: Macro to Sum Cells in Two Columns

Originally Posted by alansidman
Show us an example of your data and the expected solution. Be more specific in your explanation using your sample data for reference.

I would like a macro to find Cols B and C and enter summed total in col E

 Col1 FIND Col2 FIND Col3 Col4 Put Total of B and C In Here 1 1 1 1 2 2 2 2 2 4 3 3 3 3 6 4 4 4 4 8 5 5 5 5 10

Hope this helps

4. ## Re: Macro to Sum Cells in Two Columns

Code:
```Sub TheOddGirl()
Dim Fnd1 As Range, Fnd2 As Range, Cl As Range
Dim NxtCol As Long, i As Long

Set Fnd1 = Range("1:1").Find("Longitude", , , xlWhole, , , False, , False)
Set Fnd2 = Range("1:1").Find("Northing", , , xlWhole, , , False, , False)
If Fnd1 Is Nothing Or Fnd2 Is Nothing Then Exit Sub
NxtCol = Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Column
For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
Cells(i, NxtCol) = Cells(i, Fnd1.Column) + Cells(i, Fnd2.Column)
Next i
End Sub```
Change search values in red to suit.

5. ## Re: Macro to Sum Cells in Two Columns

Hi,

Thank you so much that works perfect.

I'll adapt it for my needs and it will save me so much time each week.

Once again thank you so much, your'e a star x

6. ## Re: Macro to Sum Cells in Two Columns

You're welcome & thanks for the feedback

7. ## Re: Macro to Sum Cells in Two Columns

Code:
```Sub Macro4()
Dim n As Long
n = Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Column
With Range(Cells(2, n), Cells(Range("A" & Rows.Count).End(xlUp).Row, n))
.FormulaR1C1 = "=IFERROR(INDEX(RC1:RC" & n - 1 & ",0,MATCH(""HEAD1"",R1,0))+" & _
"INDEX(RC1:RC" & n - 1 & ",0,MATCH(""HEAD2"",R1,0)),"""")"
.Value = .Value
End With
End Sub```

8. ## Re: Macro to Sum Cells in Two Columns

Here's a formula (can also be run from a macro like Fluff and Dante's):

Excel 2010
ABCDE
1Col1Include1Include2Col4Put Total of B and C In Here
212618
323174
4386914
5465111
6519110

Sheet1

Worksheet Formulas
CellFormula
E2=SUM(SUMIF(\$B\$1:\$D\$1,{"Include1";"Include2"},B2:D2))