+ Reply to Thread
Results 1 to 3 of 3

macro horizontal count after filter

Hybrid View

  1. #1
    Registered User
    Join Date
    12-01-2007
    Posts
    10

    Exclamation macro horizontal count after filter

    hello,

    im a newbie with macros. I needed to do a horizontal filter with my data, I did using this design:

    http://blog.livedoor.jp/andrewe/archives/50283818.html

    but now I need to do a count for each item after the filter is performed, so when a columm is hidden after the filter I need to count how many remain. Any help is greatly appreciated.
    Last edited by gtg653t; 12-03-2007 at 05:22 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello gtg653t,

    This macro will return the count of visible columns when the filter is applied. Copy this code and add paste it into Module1 of your project. You can call use this a worksheet function or call inside your VBA code.
    Function VisibleColumns() As Long
      
      Application.Volatile 
    
      Dim N As Long, C As Long
      
        C = 3
        Do
          With ActiveSheet.Cells(2, C)
            If .Value = "" Then Exit Do
            If .EntireColumn.Hidden = False Then
                N = N + 1
            End If
          End With
          C = C + 1
        Loop
        
        VisibleColumns = N
        
    End Function
    Example
    'Using it like a Worksheet formula
     =VisibleColumns()
    
    'Calling it inside VBA
     N = VisibleColumns
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    12-01-2007
    Posts
    10

    Talking Thanks =)

    Thank You!!!!

+ 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