+ Reply to Thread
Results 1 to 9 of 9

VBA to identify certain text in a data validation field

  1. #1
    Registered User
    Join Date
    11-20-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    16

    VBA to identify certain text in a data validation field

    I am trying to write an IF statement that looks at a data validation field ("A2") on a worksheet named "Select". If the data validation field contains the word "all" do nothing otherwise do something (turn autofilter). In searching posts I have not found the correct code to look at the data validation field and identify the text within it to work in the if statement. Can someone help me with this if statement?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Why not look at the value in the cell?
    If posting code please use code tags, see here.

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: VBA to identify certain text in a data validation field

    Perhaps something like

    Please Login or Register  to view this content.
    Alf

  4. #4
    Registered User
    Join Date
    11-20-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: VBA to identify certain text in a data validation field

    trying to but the cell doesn't seem to be recognized

  5. #5
    Registered User
    Join Date
    11-20-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: VBA to identify certain text in a data validation field

    Here is another one. Same issue. Sheet Select Range "A2" is equal to "All" but the code just keeps skipping to the Else statement. My guess is that it is not recognizing the value in the data validation list which is in cell "A2"
    With Sheets("Billings Data")

    .AutoFilterMode = False
    .Range("BiData").AutoFilter
    If InStr(Sheets("Select").Range("A2"), "All") Then
    .Range("BiData").AutoFilter Field:=17
    Else
    .Range("BiData").AutoFilter Field:=17, Criteria1:=Sheets("Select").Range("A2")

    End If
    End With

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Is it "All' or 'all'?

  7. #7
    Registered User
    Join Date
    11-20-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: VBA to identify certain text in a data validation field

    I just figured this out. Finally! It is case sensitive and it is "ALL". Now it works. Thanks for your replies

  8. #8
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: VBA to identify certain text in a data validation field

    If cell A2 only contains "ALL" or not then you don't need the InStr function as this finds a specified part of a string in a string. Instead you could use

    Please Login or Register  to view this content.
    Alf

  9. #9
    Registered User
    Join Date
    11-20-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: VBA to identify certain text in a data validation field

    Yes, thank you I have already changed it. Boy did that silly thing stump me for two days! I appreciate your responses.

+ 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. Replies: 10
    Last Post: 08-15-2012, 10:20 AM
  2. Using Data Validation to query a field?
    By Cyberpawz in forum Excel General
    Replies: 3
    Last Post: 04-12-2012, 12:11 PM
  3. Field Data Validation in VBA Forms - Here's a way
    By Greg Glynn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2006, 12:00 AM
  4. Cycle through data validation field and print
    By AK in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-30-2005, 08:50 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