+ Reply to Thread
Results 1 to 4 of 4

Thread: sorting and filtering and removing hidden records

  1. #1
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    sorting and filtering and removing hidden records

    Hey all,

    The below excel macro filters and sorts data BUT when I try to export the file, all the hidden cells return, even though I want the hidden cells destroyed:
    Sub Sortarific()
    '
    ' Sort and Filter
    '
    
    '
        ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$E$429"), , xlNo).Name = _
            "Table1"
        Range("Table1[#All]").Select
        ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight1"
        ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:= _
            "=Real Prop*", Operator:=xlAnd
        ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=2, Criteria1:= _
            "=DF*", Operator:=xlAnd
        ActiveWorkbook.ActiveSheet.ListObjects("Table1").Sort. _
            SortFields.Clear
        ActiveWorkbook.ActiveSheet.ListObjects("Table1").Sort. _
            SortFields.Add Key:=Range("Table1[[#All],[Column5]]"), SortOn:= _
            xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.ActiveSheet.ListObjects("Table1"). _
            Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Columns("A:B").Select
        Selection.EntireColumn.Hidden = True
        Rows("1:1").Select
        Range("Table1[[#Headers],[Column3]]").Activate
        Selection.EntireRow.Hidden = True
       
    End Sub
    Is there a way where I can sort and filter similarly in Access but not have the issue where all the filtered fields remain when I try to export the data or perform a query against other data sets without having to worry that the filtered criteria will make its presence again?

    Thanks for response.

  2. #2
    Valued Forum Contributor alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Lake County, Illinois
    MS-Off Ver
    MS Office 2010, 2007 and 2002
    Posts
    1,161

    Re: sorting and filtering and removing hidden records

    If you run a query in Access, you select which fields you wish to display in your query. So if there are fields in your table that you do not wish to show in the query, then you either omit them from the query or if you need them for joining to another table, you just indicate that the field should not be displayed. If you then export the query results to Excel or some other software package, it will only export the displayed fields.

    Alan

  3. #3
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: sorting and filtering and removing hidden records

    The problem is there is a sequence of events. We must:
    SELECT * FROM Table1 WHERE Table1.ColumnA LIKE '%Real Prop' && Table1.ColumnB LIKE '%DF' ORDER BY Table1.MI ASC;
    That's pretty much MySQL. I'm struggling how to do something like this in Access. I picked up an "essentials" book in access and it shows you the design view where you can specify criteria for particular fields, but it's not giving me an impression of a sequence of events where you do something and then something else.

    Thanks for response.

  4. #4
    Valued Forum Contributor alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Lake County, Illinois
    MS-Off Ver
    MS Office 2010, 2007 and 2002
    Posts
    1,161

    Re: sorting and filtering and removing hidden records

    but it's not giving me an impression of a sequence of events where you do something and then something else.
    I am not sure what you are alluding to here. Could you be more specific. If you are referring to running one query and then take action on that query and then take subsequent action on the second query, then you cannot do that all in one query. You will have to sequence your queries. This can be done in the QBE. Run your first query. Then create a second query which is based upon the first query and not on the original table(s). Do this until you get the expected results.

    If I missed what you are looking for, post back with more information and perhaps with some sample data with expected results. That always helps to clear the matter.

    Alan

+ 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.2.0