# Adding Formulas to Calculate Balances

Learn how to add formulas to calculate balances in your checkbook register using C# and VB with Spread.NET.

## Content

Your checkbook register is now set up to look like a checkbook register; however, it does not balance the currency figures you enter in the register. This step sets up the formula for balancing the figures.

1. Provide the following code in the Form Load event after the code you have already added:
    **Example**

    ```csharp
    // Set formula for calculating balance.
    fpSpread1.Sheets[0].ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;
    int i;
    for (i = 0; i <= fpSpread1.ActiveSheet.RowCount - 1; i++)
    {
    if (i == 0)
    fpSpread1.Sheets[0].Cells[i, 7].Formula = "RC[-1] - RC[-2]" ;
    else
    fpSpread1.Sheets[0].Cells[i, 7].Formula = "RC[-1] - RC[-2] + R[-1]C";
    }
    ```

    ```vbnet
    ' Set formula for calculating balance.
    fpSpread1.Sheets(0).ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
    Dim i As Integer
    For i = 0 To fpSpread1.ActiveSheet.RowCount - 1
    If i = 0 Then
    fpSpread1.Sheets(0).Cells(i, 7).Formula = "RC[-1] - RC[-2]"
    Else
    fpSpread1.Sheets(0).Cells(i, 7).Formula = "RC[-1]-RC[-2]+R[-1]C"
    End If
    Next
    ```
2. Save your project, then click the **Start** button in the toolbar to run your project.
3. Your form should look similar to the following picture. Type data into your checkbook register to test it and see how it operates.
    ![Completed register with data](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/checkbook3.png)
4. You have created a checkbook register using Spread. You have completed this tutorial.

Review the list of steps for [Tutorial: Creating a Checkbook Register](/spreadnet/docs/latest/online-win/overview/PowerTools_Help19/spwin-tutor-cbr).