+ Reply to Thread
Results 1 to 14 of 14

AutoFilter 0's & Non-Blanks

  1. #1
    Registered User
    Join Date
    05-02-2006
    Posts
    95

    AutoFilter 0's & Non-Blanks

    Hello Experts,
    I need your help please. The following the code from the macro recorder. Is there a better way to execute this task in proper VBA code?

    How do you add an [If...Then] critieria when 0 or 0.00 are not found, then continue to search for the next criteria, Non-Blanks?

    I have 2 more questions within this code:

    Please Login or Register  to view this content.
    Thanks in advance,
    Ricky
    Last edited by ExcelQuestion; 10-05-2008 at 10:08 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You don't need to use Select. Try this, I haven't tested it

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    For Q1, try changing Roy's:
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  4. #4
    Registered User
    Join Date
    05-02-2006
    Posts
    95
    Quote Originally Posted by royUK View Post
    You don't need to use Select. Try this, I haven't tested it

    Please Login or Register  to view this content.
    Thank-you RoyUK and broro183,
    I have ran your codes. It errors at the 3rd line from the bottom.

    Please Login or Register  to view this content.
    It also errors because the entire Row 1 will be deleted. I'd like to retain the title row. The problem has something to do with this line. When there's no match to the filter criteria, it would still delete the visible row...with is row 1.

    Please Login or Register  to view this content.
    I need more help please.

    Thanks in advance again,
    Ricky
    Last edited by ExcelQuestion; 09-21-2008 at 04:28 AM.

  5. #5
    Registered User
    Join Date
    05-02-2006
    Posts
    95
    After some trial and testing, this code seems to work okay. How do I add another filter criteria deleting all rows with "0.00" under the "ExportTotal" name? By the way, what does Option Explicit do? The code seems to work with or without it.

    Please Login or Register  to view this content.
    Thanks again,
    Ricky

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Please Login or Register  to view this content.
    is used to force you to declare variables which is good coding practice. See link for more

    http://msdn.microsoft.com/en-us/libr...4f(VS.80).aspx

    See link under More than two criteria
    http://www.rondebruin.nl/delete.htm#AutoFilter

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this slightly amended code

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-02-2006
    Posts
    95
    Hello RoyUK,
    I've tried your amended code. It did not filter the 0 nor the Blanks, and it still deleted the top Title row. You've provided a platform for me though.

    With RoyUK, broro183, and VBANoob's guidance, this is the code that does work.

    Please Login or Register  to view this content.
    I appreciate everyone's valuable input. Thanks a lot.

    Ricky

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Your on error line needs moving

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-02-2006
    Posts
    95
    Quote Originally Posted by royUK View Post
    Your on error line needs moving

    Please Login or Register  to view this content.

    Thanks RoyUK,
    I've also updated the next 2 lines. It seems to work okay, but is this right?

    Please Login or Register  to view this content.
    Ricky

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    05-02-2006
    Posts
    95
    Thanks again RoyUK.

    How do you change the last line within the existing code...

    Please Login or Register  to view this content.
    ...so that in case if I were to insert columns then the range selection would remain unchanged? It's the 65536,18 (column J) part that's written in the code and I need to make it become flexible so that the column number will change as I insert or delete columns.

    Thanks,
    Ricky

  13. #13
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    hi Ricky,

    Once a post is "solved" I think it is best to ask further questions in a new post (I stand to be corrected though... ).

    Hopefully this helps:
    Create a name for the cell in Excel by selecting the cell (I'm assuming it's a header cell with "For Export" typed into it), then press [alt + i + n + d], [Add] & [Ok] (this should create the Name "For_Export"). This name can then be used in the below code which should do what you're after...

    Please Login or Register  to view this content.
    hth
    Rob

  14. #14
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    My first reply told you that you don't need to select ranges in most cases. It also uses UsedRange which will always be the range used on the sheet, no matter how many columns or rows are added. An alternative is to use CurrentRegion.

+ 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. Autofilter with custom Dates
    By mmf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-26-2008, 04:55 PM
  2. Capturing the Excel AutoFilter Sorting Event
    By Piyush Kumar in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-04-2007, 03:14 AM
  3. Custome AutoFilter
    By nicolachen in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-21-2007, 01:53 AM
  4. AutoFilter by Rows
    By Digitborn.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-18-2007, 06:40 AM
  5. Paste autofilter results to specific region
    By feature86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2007, 12:19 PM

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