+ Reply to Thread
Results 1 to 4 of 4

SUBTOTAL and Filter Mode

Hybrid View

  1. #1
    Registered User
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    368

    SUBTOTAL and Filter Mode

    HI,

    See the file in attach.

    I have two tables in the same page that the number of rows is dynamic.
    Table2 is always 3 rows below Table1 regardless the number of rows of Table1.

    1) I need to calculate the total number of rows of each table and put the result in "E4" an "E15" regardless the number of rows of each table.

    2) If Iuse a filter or in the range("B6:E6") or range("B17:E17") and change it, I need to values in "E4" and "E15" to be updated.

    Here is some code that I was trying to use:

    
    With Application.WorksheetFunction
         Range("E4") = .Subtotal(3, Range("B7:B" & .Match("Table2", Range("B:B"), 0) - 4))
    
    End With
    Regards,
    Elio Fernandes
    Attached Files Attached Files
    Last edited by efernandes67; 07-31-2010 at 10:57 PM.

  2. #2
    Forum Contributor
    Join Date
    03-11-2010
    Location
    India
    MS-Off Ver
    2010
    Posts
    268

    Re: SUBTOTAL and Filter Mode

    Does this help?

        ' assuming first table always starts at B6
        Dim first_table_end As Integer
        Dim first_table_rows As Integer
        
        Dim second_table_start As Integer
        Dim second_table_end As Integer
        Dim second_table_rows As Integer
        
        first_table_end = Range("B6").End(xlDown).Row
        first_table_rows = first_table_end - 6 ' assuming first table always starts at B6
        
        Range("E4") = Range("B7:B" & first_table_end).SpecialCells(xlCellTypeVisible).Count ' assuming first table always starts at B6
            
        second_table_start = first_table_end + 7 'Table2 is always 3 rows below Table1, plus 4 rows of headers
        second_table_end = Range("B" & second_table_start).End(xlDown).Row
        second_table_rows = second_table_end - second_table_start ' assuming first table always starts at B6
    
        Range("E15") = Range("B" & second_table_start & ":B" & second_table_end).SpecialCells(xlCellTypeVisible).Count  ' assuming first table always starts at B6
    hth
    Ajay

  3. #3
    Registered User
    Join Date
    01-01-2005
    MS-Off Ver
    2007
    Posts
    368

    Re: SUBTOTAL and Filter Mode

    Hi Ajay,

    Your code helps but its not enough because, I need the values in "E4" and "E15" to change when I used the Filter.

    Can you give me an hand?

    Regards,
    Elio Fernandes

    Quote Originally Posted by ajaykgarg View Post
    Does this help?

        ' assuming first table always starts at B6
        Dim first_table_end As Integer
        Dim first_table_rows As Integer
        
        Dim second_table_start As Integer
        Dim second_table_end As Integer
        Dim second_table_rows As Integer
        
        first_table_end = Range("B6").End(xlDown).Row
        first_table_rows = first_table_end - 6 ' assuming first table always starts at B6
        
        Range("E4") = Range("B7:B" & first_table_end).SpecialCells(xlCellTypeVisible).Count ' assuming first table always starts at B6
            
        second_table_start = first_table_end + 7 'Table2 is always 3 rows below Table1, plus 4 rows of headers
        second_table_end = Range("B" & second_table_start).End(xlDown).Row
        second_table_rows = second_table_end - second_table_start ' assuming first table always starts at B6
    
        Range("E15") = Range("B" & second_table_start & ":B" & second_table_end).SpecialCells(xlCellTypeVisible).Count  ' assuming first table always starts at B6
    hth
    Ajay

  4. #4
    Forum Contributor
    Join Date
    03-11-2010
    Location
    India
    MS-Off Ver
    2010
    Posts
    268

    Re: SUBTOTAL and Filter Mode

    Hello Elio

    I thought Worksheet_Calculate() event will be fired when filter criteria is changed, but that is not true.
    I hope someone on the forum can tell us which event is fired when filter criteria is changed.
    You need to copy above code in that event.

    thx
    Ajay

+ 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