+ Reply to Thread
Results 1 to 5 of 5

Subtotal method adds the grand total way further down on the sheet

  1. #1
    Registered User
    Join Date
    12-14-2012
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    2

    Subtotal method adds the grand total way further down on the sheet

    Hello

    I have a spreadsheet and I need to repeat subtotaling the rows( around 2000); everytime I do it, through macro, the Grand total is added way furhter down on the sheet; what can I do?

    Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Can you post the code and/or attach a sample workbook?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-14-2012
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Subtotal method adds the grand total way further down on the sheet

    Sure..

    <<Sub CreateJERecords(ParamArray RecInfo() As Variant)
    Dim SourceSheet As String
    Dim DestinSheet As String
    Dim ColToSorting As String
    Dim AmountCol As Long
    Dim ComboCol As Long
    Dim TotalRecAdd As String
    Dim CurrTotalCell As String
    Dim NxtCurrTotalCell As String
    Dim FCurrTotalCell As String
    Dim LCurrTotalCell As String
    Dim FNxtTotalCell As Variant
    Dim LNxtTotalCell As Variant

    SourceSheet = RecInfo(0)
    DestinSheet = RecInfo(1)
    ColToSorting = RecInfo(2)
    AmountCol = RecInfo(3)
    ComboCol = RecInfo(4)

    Sheets(SourceSheet).Activate
    ActiveSheet.Cells.Select
    Selection.Copy

    Sheets(DestinSheet).Activate
    ActiveSheet.Cells.Select
    ' ActiveSheet.Paste
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

    CutCopyMode = False

    Rows("1:1").Select
    Selection.Delete Shift:=xlUp
    ActiveSheet.Cells.Select


    Selection.Sort Key1:=Range(ColToSorting), Order1:=xlAscending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal

    Selection.Subtotal GroupBy:=ComboCol, Function:=xlSum, TotalList:=Array(AmountCol), _
    Replace:=False, PageBreaks:=False, SummaryBelowData:=True

    'identify and select information for populating the JE file

    ActiveSheet.Columns(ComboCol).Cells(2, 1).Select

    Do
    If ActiveCell.Font.Bold = True Then
    CurrTotalCell = ActiveCell.Address

    GoLeft
    GoUp
    LCurrTotalCell = ActiveCell.Address
    ActiveCell.Offset(0, -5).Select
    FCurrTotalCell = ActiveCell.Address
    TotalRecAdd = FCurrTotalCell & ":" & LCurrTotalCell
    FNxtTotalCell = Left(FCurrTotalCell, InStr(2, FCurrTotalCell, "$", vbBinaryCompare)) & _
    (CInt(Right(FCurrTotalCell, (Len(FCurrTotalCell) - InStr(2, FCurrTotalCell, "$", vbBinaryCompare)))) + 1)

    LNxtTotalCell = Left(LCurrTotalCell, InStr(2, LCurrTotalCell, "$", vbBinaryCompare)) & _
    (CInt(Right(LCurrTotalCell, (Len(LCurrTotalCell) - InStr(2, LCurrTotalCell, "$", vbBinaryCompare)))) + 1)

    NxtCurrTotalCell = FNxtTotalCell & ":" & LNxtTotalCell
    Range(TotalRecAdd).Select
    Selection.Copy

    Range(NxtCurrTotalCell).Select
    ActiveSheet.Paste
    CutCopyMode = False

    Range(CurrTotalCell).Select
    GoDown

    Else
    GoDown
    End If
    Loop Until ActiveCell.Value = "Grand Total"


    MsgBox ActiveCell.Address
    ' ActiveSheet.Outline.ShowLevels RowLevels:=2

    Range("A1").Select

    End Sub>>

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Subtotal method adds the grand total way further down on the sheet

    Could you please enclose the code in code tags?

    That will make it much easier to read.

  5. #5
    Registered User
    Join Date
    08-23-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Subtotal method adds the grand total way further down on the sheet

    I have the same issue going on. I need to subtotal a sheet with a variable number of rows. I have the macro to subtotal a sprcific number of rows (more than I need - say 150 and the actual number of rows is less than that), and when subtotalling the grand total is way below the last row. I am guessing there is a way to subtotal only the number of actual rows, but I don't know what that would be. The last bit of code is the subtotal. Here is the code:

    Please Login or Register  to view this content.

+ 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