+ Reply to Thread
Results 1 to 13 of 13

Autofilter - Run Dynamically?

  1. #1
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    397

    Autofilter - Run Dynamically?

    On the attached spreadsheet I have the following code:

    Please Login or Register  to view this content.
    my issues are:

    The second Autofilter returns a Runtime 1004 - is this because I already have an autofilter in place? If so, how do I go about combining both of them?

    And

    Is there any way to dynamically run the autofilter? It is created so that only 1 blank row is visible, but I would like the next row to become visible once the bottom blank line has a date entered into Column A.
    Attached Files Attached Files

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: Autofilter - Run Dynamically?

    Shouldn't it be A5 not A9?

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    397

    Re: Autofilter - Run Dynamically?

    Hi Dave

    Thanks for the reply.

    Yes, you are right, it should have been A5.

    Column A gets filtered when I have added your code, but Column I does not, and I get a 1004 error.

    Please Login or Register  to view this content.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: Autofilter - Run Dynamically?

    Ah yes, I had turned off the filter when I was testing it. Try this to make sure the filter is off before filtering again.

    Please Login or Register  to view this content.

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,493

    Re: Autofilter - Run Dynamically?

    Here is an edited code to hide all the arrows:
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    397

    Re: Autofilter - Run Dynamically?

    That is absolutely cracking.

    Is there any way to have then run dynamically/automatically? When I add a date into A23 I would like row 24 to appear - either as soon as I hit the return after adding the date, or when I next open the workbook allowing me to add another episode of illness

  7. #7
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,266

    Re: Autofilter - Run Dynamically?

    The attachment should solve your problems.
    Most of the code that is currently in the Sheet1 module should be in the ThisWorkbook module, but will need to be customized for that module. Because it doesn't make sense to copy code to multiple sheets with the same structure and functionality. If you can't handle the migration to ThisWorkbook, that's a topic for a separate thread.

    Artik
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    397

    Re: Autofilter - Run Dynamically?

    Hi Artik

    Thank you. I am otherwise engaged today, but will look at what you have done and see if I can work it out when I get a chance.

  9. #9
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    397

    Re: Autofilter - Run Dynamically?

    Artik

    Thank you so much. That works amazingly. Just need to work out now how to move it to ThisWorkbook. Wish me luck

    Can I ask though, why is it not a good idea to have it on the Sheet1? is it because it is easier to make future changes? or will some of the code error if the worksheet is copied?

  10. #10
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,266

    Re: Autofilter - Run Dynamically?

    From your code, I inferred that there would be multiple sheets with the same structure and functionality, and therefore the same code. So it doesn't make sense to copy the code to each sheet. In such cases, you use workbook-level events (in the ThisWorkbook module). In your case, these will be 3 events: Workbook_SheetCalculate, ..._SheetChange, ..._SheetSelectionChange. If you don't foresee other sheets in the workbook that deviate from the structure of the sheet you presented, you can transfer the bodies of these procedures to the corresponding events in ThisWorkbook. Two auxiliary procedures: AutoFilter_Example1 and Sort_Tabs_Alphabetically, should be placed in a standard module, such as Module1. One event - ..._SheetCalculate - should be slightly modified so that it does not execute too often
    Please Login or Register  to view this content.
    Since a change in one sheet can cause another sheet to recalculate as well, I added a condition so that the _Calulate event executes only in the active sheet. Because, in this case, it makes no sense for other sheets. You replace the Me keyword with the Sh variable and add a condition for when the procedure body should execute.

    After the code is moved, the code must be removed from the Sheet1 module, otherwise the events will execute twice. Once in the Sheet1 module and a second time in the Thisworkbook module.

    Artik

  11. #11
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    397

    Re: Autofilter - Run Dynamically?

    Thanks for all your help on this Artik.

    I have moved Sub Sort_Tabs_Alphabetically() to Modules/Module1, and Workbook_SheetCalculate to thisWorkbook as you suggested.

    I am going to open a new post regarding moving the Worksheet_Change and Worksheet_SelectionChange to ThisWorkbook

    regards

    Darryl

  12. #12
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    397

    Re: Autofilter - Run Dynamically?

    Quote Originally Posted by Artik View Post
    After the code is moved, the code must be removed from the Sheet1 module, otherwise the events will execute twice. Once in the Sheet1 module and a second time in the Thisworkbook module.

    Artik
    Hi Artik

    I am just about there. The code you gave me:

    Please Login or Register  to view this content.
    I can sort of see what it does, but I was wondering if there was any way of making it not so vociferous? By this I mean that I am unable to put ANYTHING into any cell in column A, I can't even Merge?Centre an entire row and add anything or it tells me to not change the date in Column A.

    It's not the end of the world as I know I can Merge/Centre B-H and omit A, but it just makes it look a little untidy.
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    397

    Re: Autofilter - Run Dynamically?

    Removed the following code to allow the over-writing of Column A

    Please Login or Register  to view this content.

+ 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. Dynamically change x & y axis mins and maxs based on dynamically changing data?
    By udf463 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2021, 03:19 PM
  2. [SOLVED] Autofilter not getting entire / Autofilter not applying to all columns
    By KarelMusa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2019, 04:45 PM
  3. Replies: 0
    Last Post: 06-22-2014, 04:18 PM
  4. Replies: 4
    Last Post: 03-16-2013, 08:33 AM
  5. Replies: 2
    Last Post: 07-06-2012, 11:42 AM
  6. AutoFilter method of Range class failed - Yet autofilter works.
    By Carlsbergen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2009, 05:43 PM
  7. Capturing the Excel AutoFilter Sorting Event-sort and autofilter options
    By Kognyto in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-11-2008, 05:36 PM

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