libreOffice calc subtotal in macro

I am trying to move from excel I need a macro to subtotal but I can only get it to bring up the dialog. What arguments is dispatcher.executeDispatch(document, “.uno:DataSubTotals”, … looking for?

This is one way:

    oFunction = createUnoService("com.sun.star.sheet.FunctionAccess")
    oSheet = ThisComponent.Sheets.getByName("YOUR-SHEET")
    myRange = oSheet.getCellRangeByName( "G41:G42" )
    myRange1 = oSheet.getCellRangeByName( "G31:G32" )
    myRange2 = oSheet.getCellRangeByName( "G36:G36" )
    dim aArgument(3) as variant
    aArgument(0)=1              'Function - "1" is for Average'
    aArgument(1)=myRange        'First Range'
    aArgument(2)=myRange1       'Second Range'
    aArgument(3)=myRange2       'Third Range'
    TotalCount = oFunction.callFunction( "SubTotal", aArgument )

aArguement may be 1, 2 or 3 depending upon the number of ranges involved. Adjust accordingly. Your result is in TotalCount. Also see this post for a list of functions.