+ Reply to Thread
Results 1 to 5 of 5

Macro for hiding rows not working

Hybrid View

  1. #1
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    38

    Macro for hiding rows not working

    Hi,

    I’ve a macro to hide certain rows if I select a value on cell J6 from a dropdown data validation list. Everything works perfect until I select the option “ALL” from the list. Once I select “ALL” on J6 the workbook stops responding and then I have to use task manager to end the process.

    Can someone please help me fix this issue with the vba code. Have attached a sample workbook along with the vba code.

    Regards,
    SWSample Data.xls

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro for hiding rows not working

    Hey there,
    Try updating you entire coding behind the Sector Dashboard to just look like this. I believe the rest might be unneccessary.


    Option Explicit
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Range("J6").Value <> "ALL" Then
        Filter_By_Sector
    Else
        Cells.EntireRow.AutoFit
    End If
    
    End Sub
    
    
    
    Sub Filter_By_Sector()
    Dim r As Long 'rows to check
    Dim Hiders As Range, Found As Range
    Dim Cond As String
    '
    'The Name you want displayed is from cell K6
    Cond = [J6].Value
    '
    Application.ScreenUpdating = False
    Call Show_All 'Unhide previous names if any
    For r = 19 To ActiveSheet.UsedRange.Rows.Count
    Set Found = Range("C" & r, "L" & r).Find(What:=Cond, _
    After:=Range("D" & r), LookIn:=xlValues, _
    LookAt:=xlPart, SearchOrder:=xlByColumns, _
    SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)
    If Found Is Nothing Then
    If Hiders Is Nothing Then
    Set Hiders = Rows(r)
    Else
    Set Hiders = Union(Hiders, Rows(r))
    End If: End If: Next r
    Hiders.EntireRow.Hidden = True
    Application.ScreenUpdating = True
    End Sub

  3. #3
    Registered User
    Join Date
    07-27-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007/2010
    Posts
    86

    Re: Macro for hiding rows not working

    I added Application.EnableEvents to your clear_filters code
    Sub Clear_Filters()
    Application.EnableEvents = False
    With Range("J6")
        
            If .Validation.Type = xlValidateList Then
                
                .Value = Split(.Validation.Formula1, ",")(0)
                
            End If
        End With
        Cells.EntireRow.Hidden = False
        With Range("G6")
        
            If .Validation.Type = xlValidateList Then
            
                .Value = Split(.Validation.Formula1, ",")(0)
            End If
        End With
    Cells.EntireRow.Hidden = False
    Application.EnableEvents = True
    End Sub
    Boon

  4. #4
    Registered User
    Join Date
    03-28-2010
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Macro for hiding rows not working

    That was quick. Thanks so much for all your help!!!!

  5. #5
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Macro for hiding rows not working

    Thanks for the star tap!

+ 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