Your code looks as though it might have an error in it: the first loop checks for "Total" in the first element ofthe array inarr which mean it is checking for "total" in column O and it writes the equation in

column O

the second loop also check for "Total" in the first element of the array so it is also checking for "total" in column O but it writes the equation in col P. this doesn't make sense to me. I think you should be checking for "total" in column P instead. To do this you need to change this line:

VBA Code:

` If inarr(i, 1) = "Total" Then`

to

VBA Code:

` If inarr(i, 2) = "Total" Then`

but only in the second loop

If you do want to write the equation in column P whenever there is "Total" in column O , you only need to have one loop, you can write both lines one after the other. See the second example

Code to check O and then P for Total

VBA Code:

```
Sub Automsum()
inarr = Range("O304:P585")
startrow = 303
For i = 1 To UBound(inarr, 1)
If inarr(i, 1) = "Total" Then
Range(Cells(303 + i, 15), Cells(303 + i, 15)).Formula = "=Sum(" & "O" & startrow + 1 & ":O" & i + 302 & " )"
startrow = i + 303
End If
Next i
startrow = 303
For i = 1 To UBound(inarr, 1)
If inarr(i, 2) = "Total" Then
Range(Cells(303 + i, 16), Cells(303 + i, 16)).Formula = "=Sum(" & "P" & startrow + 1 & ":P" & i + 302 & " )"
startrow = i + 303
End If
Next i
End Sub
```

Code to do what your code does but faster

VBA Code:

```
Sub Automsum()
inarr = Range("O304:P585")
startrow = 303
For i = 1 To UBound(inarr, 1)
If inarr(i, 1) = "Total" Then
Range(Cells(303 + i, 15), Cells(303 + i, 15)).Formula = "=Sum(" & "O" & startrow + 1 & ":O" & i + 302 & " )"
Range(Cells(303 + i, 16), Cells(303 + i, 16)).Formula = "=Sum(" & "P" & startrow + 1 & ":P" & i + 302 & " )"
startrow = i + 303
End If
Next i
End Sub
[/QUOTE]
```