+ Reply to Thread
Results 1 to 4 of 4

If then else on an autofilter - syntax issues

  1. #1
    Registered User
    Join Date
    02-01-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2010
    Posts
    97

    If then else on an autofilter - syntax issues

    Hi Everyone,

    I seem to be pestering you all daily at the minute so apologies.

    Im trying to apply an autofilter to a column based on the value in cell D2. Heres what I have.......

    [CODE][/Sub Filterfirstvalue()

    Dim station As Range
    firstvalue = Range("D2").Value

    If firstvalue = "All" Then ActiveSheet.Range("$B$8:$DV$314").AutoFilter
    ElseIf ActiveSheet.Range("$B$8:$DV$314").AutoFilter Field:=3, Criteria1:=Range("D2")

    End SubCODE]

    Im struggling with the else portion I think.

    In short, I want to input "4" in cell D2 - Only the "4"'s are shown. I am fine with this bit as I have recorded that.
    I also want to be able to leave the cell blank, alternatively type "All", or something similar, and everything will be shown again. This is where I fail.

    Please can you help?

    Im starting to realise that I am not a natural VBA'er!

    Kind regards
    Alex

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: If then else on an autofilter - syntax issues

    Does this help?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-01-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2010
    Posts
    97

    Re: If then else on an autofilter - syntax issues

    Thanks John,

    It works perfectly, thanks for all your help!

    Thanks again
    Alex
    Last edited by cossie2k; 02-11-2016 at 11:12 AM.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: If then else on an autofilter - syntax issues

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. VBA SUMIF syntax issues
    By lordterrin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-31-2014, 06:38 PM
  2. IF, AND & OR Syntax Issues
    By Steve0492 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2013, 06:22 AM
  3. VBA - Autofilter issues
    By gtiguy in forum Excel General
    Replies: 0
    Last Post: 11-23-2012, 07:28 PM
  4. [SOLVED] Autofilter Syntax
    By stockgoblin42 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-22-2012, 08:30 AM
  5. IF/THEN Syntax issues
    By EdinNH in forum Excel General
    Replies: 6
    Last Post: 06-12-2012, 05:21 PM
  6. Syntax issues with the OR function
    By aikorei in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-10-2007, 04:35 PM
  7. autofilter syntax in VBscript
    By Bob S in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-30-2006, 12:15 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