Macro returning sum as "0"

hello, there are a few issues with this code, so any help is very welcome:

Sub SumBeforeBlank()
    Dim oSheet As Object
    Dim oCell As Object
    Dim nSum As Double
    Dim nRow As Long
    oSheet = ThisComponent.CurrentController.ActiveSheet
    For nRow = 1 To oSheet.Rows.Count
        oCell = oSheet.getCellByPosition(0, nRow)
        If oCell.Type = Then
            oSheet.getCellByPosition(1, nRow).setValue(nSum)
            nSum = 0
            nSum = nSum + oCell.getValue()
        End If
    Next nRow
End Sub


The yellow highlight is where I need the sums for the blocks of data.

Thank you.

Fix your ask - something is wrong in your JPG now :frowning:

Fwiw, I formatted the code as code… see This is the guide - How to use the Ask site? - #6 by erAck.

1 Like

thank you. Sorry

this is the pic that isnt working.

Think about why do you use column 1 when setting the cell value, but column 0 when getting the summed values.

1 Like

So I’m basically telling it to look at two different things…but they should be the same thing? I will see if I can rewrite it. thank you.

Thank you!! I figured it out.

1 Like