+ Reply to Thread
Results 1 to 5 of 5

VBA to filter multiple sheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-01-2008
    Location
    Perth, Australia
    MS-Off Ver
    Excel 365
    Posts
    135

    VBA to filter multiple sheets

    Hi All,

    I have a macro that filters all the sheets in a workbook based on a cell entry on sheet 1. The filter runs through Columns 1.

    This works quite well(other than flicker issues).

    The problem is I also need the filter to run through column K and show rows that have an empty cell.(i.e UnInvoiced) I have tried the below code, but it shows the empty formula rows below all data not the uninvoiced rows.
    ElseIf RLetter = "Uninvoiced" And w.AutoFilterMode Then
    w.Unprotect Password:="test"
    w.Range("K3").AutoFilter Field:=11, Criteria1:=""
    Please Help

    Cheers

    Adam
    Last edited by VBA Noob; 09-24-2008 at 01:24 AM. Reason: Poor title

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Hi Zimbo .. others may have a different view, but for me, it's difficult to help without seeing the full code and trying to work out what's happening with 3 lines of code, those being only part of a conditional statement ... well, it could be anything really and may not even be in these lines. If you'd like to post it or prefaerably attach your workbook, I'll take a look for you. Are you applying these filters on A and then K? Depending on your data, they may be incompatible ..

    On the flicker issues when filtering sheets - have you used:
    Application.ScreenUpdating = False
    Just don't forget to turn it back on again ..

    Cheers, MM.

  3. #3
    Forum Contributor
    Join Date
    02-01-2008
    Location
    Perth, Australia
    MS-Off Ver
    Excel 365
    Posts
    135

    Red face Please see new post

    Hi All,

    Accidently posting newer post is correct.
    Last edited by Zimbo; 09-25-2008 at 09:20 AM. Reason: Incorrect Posting

  4. #4
    Forum Contributor
    Join Date
    02-01-2008
    Location
    Perth, Australia
    MS-Off Ver
    Excel 365
    Posts
    135

    My Code

    Hi MM,

    I have managed to fix the flicker issues ( I was calling macros in the wrong places). Please find my code for the sheet sort below.
    I am either sorting by Column A or Column K, but should not sort Column K unless Column A has a value. I have tried the sort criteria as both ="" and ="=".

    Sub DoFilters()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    Dim w As Worksheet, RLetter As String
    Dim Crit As String
    Crit = Sheets("TOTALS").Range("DateRange").Value
    RLetter = Crit
    For Each w In Worksheets
    
    If w.Index > 2 Then
    If RLetter = "Year To Date" And w.AutoFilterMode Then
    w.Unprotect Password:="test"
    w.AutoFilterMode = False
    w.Protect Password:="test", DrawingObjects:=True, Contents:=True, Scenarios:=True
    
    
    ElseIf RLetter = "Uninvoiced" And w.AutoFilterMode Then
    w.Unprotect Password:="test"
    w.Columns("K").AutoFilter Field:=1, Criteria1:="", Visibledropdown:=True
    w.Protect Password:="test", DrawingObjects:=True, Contents:=True, Scenarios:=True
    
    ''w.Range("A1").SpecialCells(xlCellTypeLastCell).AutoFilter Field:=11, Criteria1:="="
    
    Else
    
    w.Unprotect Password:="test"
    w.Range("A1").End(xlDown).AutoFilter Field:=1, Criteria1:=Crit, Visibledropdown:=True
    w.Protect Password:="test", DrawingObjects:=True, Contents:=True, Scenarios:=True
    
    On Error Resume Next
    End If
    
    'w.Protect Password:="test", DrawingObjects:=True, Contents:=True, Scenarios:=True
    End If
    Next
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Call Refresh_Click
    End Sub
    The section "Uninvoiced" is the one I am having issues with.

    All help is appreciated.

    Cheers

    Adam
    Last edited by Zimbo; 09-25-2008 at 09:42 AM.

  5. #5
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    If I understand correctly that you're trying to filter first on col A for non-blanks and then any blanks in col K, try this:

    ElseIf Crit = "Uninvoiced" And w.AutoFilterMode = True Then
        w.Range("A1").AutoFilter Field:=1, Criteria1:="<>", visibledropdown:=True
        w.Range("A1").AutoFilter Field:=11, Criteria1:="=", visibledropdown:=True
    I'm not sure why you've got specialcells etc in there; if the autofilter is on the range for the filter is implied and you don't need to specify it.

    Hope that helps. MM.
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 05-28-2008, 03:12 AM
  2. Massive Sorting question.
    By Rgaherty in forum Excel Programming / VBA / Macros
    Replies: 35
    Last Post: 11-07-2007, 02:15 PM
  3. Separating CSV text from one column into sorted column
    By Terrance in forum Excel General
    Replies: 2
    Last Post: 11-02-2007, 10:39 AM
  4. looping issues
    By Marcus Gee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-09-2007, 11:42 PM
  5. Replies: 5
    Last Post: 06-06-2007, 07:27 AM

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