excelvbaexcel-tableslistobject

Vba Number Format for only Totals Calculation for ListObject


I want to create a custom currency number format only in the total row table if there is a solution and which I mark the yellow color in the screenshot.

Thanks jack

Sub test2()
Dim objListObj As ListObject
Set objListObj = Sheets("test").ListObjects(1)
objListObj.ShowTotals = True
With Sheets("test").ListObjects("Table1")
.ListColumns("Total").TotalsCalculation = xlTotalsCalculationSum
.ListColumns("Pot. :").TotalsCalculation = xlTotalsCalculationSum
.ListColumns("Total End :").TotalsCalculation = xlTotalsCalculationSum
.ListColumns("PRICE2").TotalsCalculation = xlTotalsCalculationSum
End With
End Sub

SHEET TEST 25022022


Solution

  • Excel Table (ListObject): TotalsCalculation & TotalsRowRange

    Option Explicit
    
    Sub test2()
        
        Dim Headers As Variant
        Headers = Array("Total", "Pot. :", "Total End :", "PRICE2")
        
        With ThisWorkbook.Worksheets("test").ListObjects("Table1")
            .ShowTotals = True
            Dim n As Long
            For n = LBound(Headers) To UBound(Headers)
                With .ListColumns(Headers(n))
                    .TotalsCalculation = xlTotalsCalculationSum
                    .Parent.TotalsRowRange.Columns(.Index) _
                        .NumberFormat = "#,##0.00 $"
                End With
            Next n
        End With
    
    End Sub