+ Reply to Thread
Results 1 to 7 of 7

Autosum

Hybrid View

  1. #1
    Registered User
    Join Date
    03-09-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    35

    Question Autosum

    Okay guys, I'm stymied on this one. I've been working on creating an auto-reporting tool and I'm stuck.

    I have been working in a "scratchbook" (book4.xlsm) to ensure that I have proper coding before importing it into my final product.

    My line of code says to run the data table through a series of filters, autosum the results and then paste them into a cell on the summary page. Then, it resets the filters and runs the data through the process again, changing the filters and the output cell destination.

    In Book4.xlsm the macro works EXACTLY like it is supposed to. So, I copied the macro coding and pasted into the "reporting tool.xlsm". I included the lines to activate the "Monthly report.xls" and the correct sheet and select a cell in the data range. I even left the auto-refresh update ON so that I could see what's happening.

    Now, the coding does NOT work properly. it's EXACTLy the same code from book4, but it doesnt work. It's supposed to only be auto-summing the VISIBLE cells. But now, it's returning a random number. At first I thought that it was returning the results for ALL of column N, visible and hidden, but even that isnt the case. The results for Column N when auto-summed manually are "74918.28", however the macro is returning a result of "230144.65" and I cannot ascertain where that figure is coming from. Additionally, it's returing this same value for every single filter.

    I'm stuck. Please, please help!

    The code is below:

    ******************************************
    Sub Calculate()
    
    Call RVRTotals
    
    
    End Sub
    
    Sub RVRTotals()
    
    Windows("Monthly Finance Report.xls").Activate
    Sheets("RVR Detail").Select
    Range("A3").Select
    
    Call RVR_GMH_NonXIX
    Call RVR_GMH_XIX
    Call RVR_GMH_XXI
    
    Call RVR_SMI_NonXIX_Cenpatico
    Call RVR_SMI_XIX_Cenpatico
    Call RVR_SMI_XXI_Cenpatico
    
    Call RVR_SMI_NonXIX_Apache
    Call RVR_SMI_XIX_Apache
    Call RVR_SMI_XXI_Apache
    
    Call RVR_SMI_NonXIX_NARBHAFFS
    Call RVR_SMI_XIX_NARBHAFFS
    Call RVR_SMI_XXI_NARBHAFFS
    
    Sheets("Summary").Select
    
    
    End Sub
    
    Sub RVR_GMH_NonXIX()
    
    ' Subtotals RVR GMH Non-XIX values
    Range("a3").Select
    
        Selection.AutoFilter
        Selection.AutoFilter Field:=7, Criteria1:="GMH"
        Selection.AutoFilter Field:=6, Criteria1:="Non XIX"
    
    Dim b As Range
     
    ' create range in column N from row 2 to the last visible cell with data
    With Sheet1
        Set b = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
     
    Range("S1").Value = WorksheetFunction.Sum(b.SpecialCells(xlCellTypeVisible))
    
    Range("S1").Select
    Selection.Copy
    
    Worksheets("Summary").Activate
    Range("E10").PasteSpecial
    Worksheets("RVR Detail").Activate
    Selection.AutoFilter
    
    End Sub
    
    Sub RVR_GMH_XIX()
    
    ' Subtotals RVR GMH Non-XIX values
    Range("A3").Select
    
    
        Selection.AutoFilter Field:=7, Criteria1:="GMH"
        Selection.AutoFilter Field:=6, Criteria1:="XIX"
    
    Dim a As Range
     
    ' create range in column N from row 2 to the last visible cell with data
    With Sheet1
        Set a = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
     
    Range("S1").Value = WorksheetFunction.Sum(a.SpecialCells(xlCellTypeVisible))
    
    Range("S1").Select
    Selection.Copy
    
    Worksheets("Summary").Activate
    Range("F10").PasteSpecial
    Worksheets("RVR Detail").Activate
    Selection.AutoFilter
    
    End Sub
    Sub RVR_GMH_XXI()
    
    ' Subtotals RVR GMH Non-XIX values
    Range("a3").Select
    
        Selection.AutoFilter Field:=7, Criteria1:="GMH"
        Selection.AutoFilter Field:=6, Criteria1:="XXI"
    
    Dim a As Range
     
    ' create range in column N from row 2 to the last visible cell with data
    With Sheet1
        Set a = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
     
    Range("S1").Value = WorksheetFunction.Sum(a.SpecialCells(xlCellTypeVisible))
    
    Range("S1").Select
    Selection.Copy
    
    Worksheets("Summary").Activate
    Range("G10").PasteSpecial
    Worksheets("RVR Detail").Activate
    Selection.AutoFilter
    
    End Sub
    
    
    
    
    
    Sub RVR_SMI_NonXIX_Cenpatico()
    
    ' Subtotals RVR GMH Non-XIX values
    Range("a3").Select
    
        Selection.AutoFilter Field:=7, Criteria1:="SMI"
        Selection.AutoFilter Field:=6, Criteria1:="Non XIX"
        Selection.AutoFilter Field:=1, Criteria1:="Cenpatico"
        
    
    Dim a As Range
     
    ' create range in column N from row 2 to the last visible cell with data
    With Sheet1
        Set a = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
     
    Range("S1").Value = WorksheetFunction.Sum(a.SpecialCells(xlCellTypeVisible))
    
    Range("S1").Select
    Selection.Copy
    
    Worksheets("Summary").Activate
    Range("E11").PasteSpecial
    Worksheets("RVR Detail").Activate
    Selection.AutoFilter
    
    End Sub
    Sub RVR_SMI_XIX_Cenpatico()
    
    ' Subtotals RVR GMH Non-XIX values
    Range("a3").Select
    
        Selection.AutoFilter Field:=7, Criteria1:="SMI"
        Selection.AutoFilter Field:=6, Criteria1:="XIX"
        Selection.AutoFilter Field:=1, Criteria1:="Cenpatico"
        
    
    Dim a As Range
     
    ' create range in column N from row 2 to the last visible cell with data
    With Sheet1
        Set a = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
     
    Range("S1").Value = WorksheetFunction.Sum(a.SpecialCells(xlCellTypeVisible))
    
    Range("S1").Select
    Selection.Copy
    
    Worksheets("Summary").Activate
    Range("F11").PasteSpecial
    Worksheets("RVR Detail").Activate
    Selection.AutoFilter
    
    End Sub
    Sub RVR_SMI_XXI_Cenpatico()
    
    ' Subtotals RVR GMH Non-XIX values
    Range("a3").Select
    
        Selection.AutoFilter Field:=7, Criteria1:="SMI"
        Selection.AutoFilter Field:=6, Criteria1:="XXI"
        Selection.AutoFilter Field:=1, Criteria1:="Cenpatico"
        
    
    Dim a As Range
     
    ' create range in column N from row 2 to the last visible cell with data
    With Sheet1
        Set a = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
     
    Range("S1").Value = WorksheetFunction.Sum(a.SpecialCells(xlCellTypeVisible))
    
    Range("S1").Select
    Selection.Copy
    
    Worksheets("Summary").Activate
    Range("G11").PasteSpecial
    Worksheets("RVR Detail").Activate
    Selection.AutoFilter
    
    End Sub
    
    Sub RVR_SMI_NonXIX_Apache()
    
    ' Subtotals RVR GMH Non-XIX values
    Range("a3").Select
    
        Selection.AutoFilter Field:=7, Criteria1:="SMI"
        Selection.AutoFilter Field:=6, Criteria1:="Non XIX"
        Selection.AutoFilter Field:=1, Criteria1:="Apache TRBHA"
        
    
    Dim a As Range
     
    ' create range in column N from row 2 to the last visible cell with data
    With Sheet1
        Set a = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
     
    Range("S1").Value = WorksheetFunction.Sum(a.SpecialCells(xlCellTypeVisible))
    
    Range("S1").Select
    Selection.Copy
    
    Worksheets("Summary").Activate
    Range("E12").PasteSpecial
    Worksheets("RVR Detail").Activate
    Selection.AutoFilter
    
    End Sub
    Sub RVR_SMI_XIX_Apache()
    
    ' Subtotals RVR GMH Non-XIX values
    Range("a3").Select
    
        Selection.AutoFilter Field:=7, Criteria1:="SMI"
        Selection.AutoFilter Field:=6, Criteria1:="XIX"
        Selection.AutoFilter Field:=1, Criteria1:="Apache TRBHA"
        
    
    Dim a As Range
     
    ' create range in column N from row 2 to the last visible cell with data
    With Sheet1
        Set a = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
     
    Range("S1").Value = WorksheetFunction.Sum(a.SpecialCells(xlCellTypeVisible))
    
    Range("S1").Select
    Selection.Copy
    
    Worksheets("Summary").Activate
    Range("F12").PasteSpecial
    Worksheets("RVR Detail").Activate
    Selection.AutoFilter
    
    End Sub
    (Truncated due to length)....all the rest is the same as above...
    Last edited by JohnathanC; 03-10-2010 at 04:37 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Autosum

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    I've added the tags this time,but be sure to read & follow the rules
    Last edited by royUK; 03-09-2010 at 03:33 PM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Autosum

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

    Without seeing the data layout it's difficult, but probably a PivotTable would be better & more efficient, especially as your code is not written with efficiency in mind

  4. #4
    Registered User
    Join Date
    03-09-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Autosum

    Hi Roy,

    Sorry about the coding thing..I wasnt aware. I figured out my issue though, thanks.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Autosum

    Your post does not comply with Rule 9 of our Forum RULES. If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit. And please never edit a thread in which someone else has responded.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  6. #6
    Registered User
    Join Date
    03-09-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Autosum

    ? .... I didnt edit anything?

  7. #7
    Registered User
    Join Date
    03-09-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Autosum

    OKay then, as per "Rule 9", here was my solution.

    I had one workbook RUNNING the macro, and pasting the information into an "output" file. Here's what I wrote.

    Sub RVR_GMH_NonXIX()
    
    ' Subtotals RVR GMH Non-XIX values
    Range("a3").Select
    
        Selection.AutoFilter
        Selection.AutoFilter Field:=7, Criteria1:="GMH"
        Selection.AutoFilter Field:=6, Criteria1:="Non XIX"
    
    Dim b As Range
     
    ' create range in column N from row 2 to the last visible cell with data
    With Sheet1
        Set b = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
     
    Range("S1").Value = WorksheetFunction.Sum(b.SpecialCells(xlCellTypeVisible))
    
    Range("S1").Select
    Selection.Copy
    
    Worksheets("Summary").Activate
    Range("E10").PasteSpecial
    Worksheets("RVR Detail").Activate
    Selection.AutoFilter
    
    End Sub
    What ended up happening with that was that the file executing the code was autosumming the data in the range in that workbook instead of the range of the output file.

    The problem was here:

    With Sheet1
        Set b = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
    Since I had "activated" the output file earlier in the code I changed the code to this:

    With ActiveSheet
        Set b = .Range("N2", .Range("N" & .Rows.Count).End(xlUp))
    End With
    and Bob's your uncle.

+ 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