+ Reply to Thread
Results 1 to 6 of 6

cumulative addition macro edit

Hybrid View

  1. #1
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    395

    cumulative addition macro edit

    Hi all i needed some help with the macro i am using which subtotal workbook & certain columns.. but what i want to be able to do is have a cummulative total instead of subtotals would that be possible.. regards

    Public Sub InstallSubtotals()
    Dim ws As Worksheet
    Application.DisplayAlerts = False
    Range("A3").Select
    For Each ws In ActiveWorkbook.Worksheets
        If IsNumeric(ws.Name) Then
            With ws
                .UsedRange.RemoveSubtotal
                With .Range(.Cells(2, "C"), .Cells(.Rows.Count, "C").End(xlUp).Offset(, 24))
                    .Subtotal GroupBy:=2, Function:=xlSum, _
                        TotalList:=Array(7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), _
                            Replace:=True, PageBreaks:=False, SummaryBelowData:=True
                End With
                .Outline.ShowLevels RowLevels:=2
                On Error Resume Next
                With .Cells(.Rows.Count, "D").End(xlUp).Resize(, 24)
                    .SpecialCells(xlCellTypeBlanks).EntireColumn.Hidden = True
                    .SpecialCells(xlCellTypeVisible).Borders(xlEdgeTop).Weight = xlThin
                End With
                On Error GoTo 0
                With .Range(.Cells(4, "D"), .Cells(.Rows.Count, "D").End(xlUp).Offset(, 23)).SpecialCells(xlCellTypeVisible)
                    .Font.Bold = True
                    .Borders(xlEdgeTop).Weight = xlThin
                End With
                .Columns("D:AA").Hidden = False
            End With
        End If
    Attached Files Attached Files
    Last edited by tek9step; 09-30-2010 at 06:55 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: cumulative addition macro edit

    Try adding:
    Range("D:T").Replace "SUBTOTAL(9,", "SUM("
    to the end of the code.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    395

    Re: cumulative addition macro edit

    Hi Romperstomper.. Please see post below with attachment..
    Last edited by tek9step; 09-30-2010 at 06:29 AM.

  4. #4
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    395

    Re: cumulative addition macro edit

    I tried it didnt work.. it did change the subtotals to sum but no change on cumulative totals..
    Attached Files Attached Files
    Last edited by tek9step; 09-30-2010 at 06:30 AM.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: cumulative addition macro edit

    Sorry, having a brain fade there. Try this:
    Public Sub InstallSubtotals()
    Dim ws As Worksheet
    Dim rngCell As Range
    Dim lngRef As Long
    With Application
        .DisplayAlerts = False
        lngRef = .ReferenceStyle
        .ReferenceStyle = xlR1C1
    End With
    Range("A3").Select
    For Each ws In ActiveWorkbook.Worksheets
        If IsNumeric(ws.Name) Then
            With ws
                .UsedRange.RemoveSubtotal
                With .Range(.Cells(2, "C"), .Cells(.Rows.Count, "C").End(xlUp).Offset(, 24))
                    .Subtotal GroupBy:=2, Function:=xlSum, _
                        TotalList:=Array(7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), _
                            Replace:=True, PageBreaks:=False, SummaryBelowData:=True
                End With
                .Outline.ShowLevels RowLevels:=2
                On Error Resume Next
                With .Cells(.Rows.Count, "D").End(xlUp).Resize(, 24)
                    .SpecialCells(xlCellTypeBlanks).EntireColumn.Hidden = True
                    .SpecialCells(xlCellTypeVisible).Borders(xlEdgeTop).Weight = xlThin
                End With
                On Error GoTo 0
                With .Range(.Cells(4, "D"), .Cells(.Rows.Count, "D").End(xlUp).Offset(, 23)).SpecialCells(xlCellTypeVisible)
                    .Font.Bold = True
                    .Borders(xlEdgeTop).Weight = xlThin
                End With
                .Columns("D:AA").Hidden = False
                .Range("D:T").SpecialCells(xlCellTypeFormulas).Replace "9,*:", "9,R4C:", xlPart
            End With
        End If
    
    Next ws
    With Application
        .DisplayAlerts = True
        .ReferenceStyle = lngRef
    End With
    End Sub

  6. #6
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    395

    Re: cumulative addition macro edit

    Brilliant !!! Thanks Mate... !!
    dont play hard just play right !!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1