+ Reply to Thread
Results 1 to 7 of 7

Subtotal a filtered range grrrr

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Subtotal a filtered range grrrr

    Hi all, I have a piece of code which works fine if you change the
    Criteria1
    in the macro which is not efficient as there are many filter ranges. I did comment the filter range out and just filter it manually on the spreadsheet but the formula does not get added to the cell, its fine when not filtered but as soon as it has a filter it doesnt work, thanks for the advice and help yesterday but it's still not right and I cant see whats wrong with it.


    Sub Filter_Sum()
    
    Set W1 = Worksheets("Master")
    
    Set Lastrow = W1.Cells(Rows.Count, "I").End(xlUp).Offset(2, 0)
     
     
     'With W1.Range("A1").CurrentRegion
      '  .AutoFilter
       ' .AutoFilter Field:=20, Criteria1:="340"
    'End With
    
    Lastrow.FormulaR1C1 = "=SUBTOTAL(109,R2C:R[-1]C)"
    
    
    
    End Sub
    Last edited by Hurricanefly; 05-16-2013 at 07:30 AM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Subtotal a filtered range grrrr

    if you don't unfilter the range the end(xlup) part will only find the last visible cell-that's why the .autofilter line was added before finding the last cell in the code I supplied
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Subtotal a filtered range grrrr

    Okay my bad, is there a way.of just finding the last cell without having a filter in the macro? then i could manually change it?

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Subtotal a filtered range grrrr

    perhaps
    Sub Filter_Sum()
    dim lr as long
    Set W1 = Worksheets("Master")
    With W1
    With .Range("A1").CurrentRegion
      lr = .row + .rows.count
    End With
    
    .cells(lr, "I").FormulaR1C1 = "=SUBTOTAL(109,R2C:R[-1]C)"
    end with
    End Sub

  5. #5
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Subtotal a filtered range grrrr

    Thank you for your help, again

  6. #6
    Forum Contributor
    Join Date
    05-09-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Subtotal a filtered range grrrr

    Yes this is perfect, just exactly as i need, thanks again

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Subtotal a filtered range grrrr

    you're welcome :-)

    don't forget to mark the thread solved

+ 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