+ Reply to Thread
Results 1 to 7 of 7

Advanced Filter

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-16-2009
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    116

    Advanced Filter

    I am trying to get an advanced filter to work on a table. Its a simple filter on the sheet that the data is in called Datasheet in the field there are clas numbers from 1 to 9 sometimes less but no more than 9.

    My Goal is to create a seperate table for each class on sheet 3. The table will contain an id field, name field and 5 fields calculated from data on "Datasheet" . I recorded a macro to filter data but it fails at "Field=3" in my code. "Field 3 = column C".

    If you can help with any part of the filter that would be awesome.
    Sub Filternums()
    '
    ' Filternums Macro
    '
    
    '
        Dim NumRge As String
        Dim ClassCount As Integer
        ARange = Worksheets("sheet3").Range("C:C") to LastRow
        BRange = Worksheets("sheet3").Range("D:D") to LastRow
    '   NewTable = Worksheets("sheet3").LastRow + 1 Row
        x = 1 <= 9
        NumRge = .ListObjects("Table2").Range.AutoFilter Field:=3, Criteria1:=x Operator:=xlAnd) ' copied from recorded macro but error at Field
        .Action:=xlFilterCopy
        With Sheets("Datasheet")
         
    '    Find the last row and return count of rows minus header
         ClassCount = Cells(Rows.Count, "C").End(xlUp).Row - 1 ' Count number of rows from Lastrow and minus 1 for header
    '    Copy list of ids and names from from column M and N to Sheet 3
    '    On next loop copy to sheet three leaving a row after last table
    '    Some Calculation for condition 1 - paste to sheet3 from C
    '    Some Calculation for condition 2 - paste to sheet3 From D
    '    Fromat sheet 3 as table 1 on next loop table 2 etc
    '    Ensure number format and data bars
    '    With
            .NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
            .FormatConditions.AddDatabar ' Add Conditional Data bars
            .FormatConditions(Selection.FormatConditions.Count).ShowValue = True
            .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
            With .FormatConditions(1)
                .MinPoint.Modify newtype:=xlConditionValueLowestValue
                .MaxPoint.Modify newtype:=xlConditionValueHighestValue
                With .BarColor
                    .Color = 13012579
                    .TintAndShade = 0
                End With
            End With
        End With
        Next x
    End Sub
    Last edited by flebber; 08-20-2010 at 07:19 AM. Reason: Update to code

  2. #2
    Forum Contributor
    Join Date
    07-16-2009
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Advanced Filter

    Hopefully to make it easeir to understand.

    Filter Column C sheet 2 ' based on class number
    insert a table in sheet 3
    copy names and id from column M & N(sheet2) to columns C & D on sheet 3
    Column B2 sheet 3 add all class scores from Column U(sheet2) and / by number in class
    Column E on sheet 3 Use individual class member score from sheet2 column U and minus it from calculated average in B2 sheet3 - as calculated above. repeat for class members
    increment autofilter by and repeat for next class starting a new seperate table with a row spacing below the previous on sheet3.
    thats what I am trying to acheive with my mess of code and sudo code above.

  3. #3
    Forum Contributor
    Join Date
    07-16-2009
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Advanced Filter

    Anyone done anythig with the advanced filter like this before?

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Advanced Filter

    Be easier if we could see a file. Also you appear to be trying to use autofilter and advanced filter at the same time? (and your code uses 'Advanced Filter' with a space, which shouldn't even compile.)
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Contributor
    Join Date
    07-16-2009
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Advanced Filter

    Quote Originally Posted by romperstomper View Post
    Be easier if we could see a file. Also you appear to be trying to use autofilter and advanced filter at the same time? (and your code uses 'Advanced Filter' with a space, which shouldn't even compile.)
    Yeah I am trying to peice it together bit by bit. The problem is it errors at field=3 which was part of the recorded code I used.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Advanced Filter

    Your code makes very little sense, which is why I asked for a file.
    For example, what is this supposed to do:
    x = 1 <= 9
    ?

  7. #7
    Forum Contributor
    Join Date
    07-16-2009
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Advanced Filter

    Quote Originally Posted by romperstomper View Post
    Your code makes very little sense, which is why I asked for a file.
    For example, what is this supposed to do:
    x = 1 <= 9
    ?
    Yeah my code is a bit of a mess because I am still really new to this.
    x = 1 <= 9
    Just supposed to make x have a value of between 1 and 9 because their are up to 9 classes in my data.

    I will work on my code a bit more and see how I go. Really what I am aiming to do is simple its me making it hard - filter, count, paste on another sheet and a quick sum ot two and go again.

    Just goes to prove newbies can make anything hard

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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