# Visual Basic > Visual Basic .NET >  [RESOLVED] Using Excel SUM formula problem

## MrPumper

The first 2 lines of code works, the last 2 lines with the variable n does not.
LOoking for help on using the SUM formula.
The  Form1.lblRecords.Text gets no higher than 50




```
Dim m As String = CStr(CInt(Form1.lblRecords.Text) + 7)
oSheet.Range("F" & m) = "Total"

Dim n As String = CStr(CInt(Form1.lblRecords.Text) + 6)
oSheet.Range("G" & m) = "=SUM(G7:G & n)"
```

----------


## OptionBase1

```
oSheet.Range("G" & m) = "=SUM(G7:G" & n & ")"
```

----------


## MrPumper

Thanks OptionBase1,  I have tried every combination except this one.  It works as I wanted.
Looking back it was very simple.

----------


## .paul.

> Thanks OptionBase1,  I have tried every combination except this one.  It works as I wanted.
> Looking back it was very simple.


It is simple. Youve got to remember which parts are string literals and which parts are variables or concatenation operators

----------


## .paul.

In the later versions of vb.net, you could do this



```
oSheet.Range($G{m}) = $"=SUM(G7:G{n})"
```

----------

