+ Reply to Thread
Results 1 to 4 of 4

An If Statement Based on a list

  1. #1
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    An If Statement Based on a list

    Hello,

    I am trying to make an if statement that can check if a value is in a list. Is there a way to do this besides going x=1 or x=2 ect.

    I am using this to fill a combobox with all of the numbers in a month based on the month selected so if there is a different method for that it would work as well.

    Thanks

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: An If Statement Based on a list

    You can use the range find method.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    06-12-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    167

    Re: An If Statement Based on a list

    What is that

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: An If Statement Based on a list

    Excel Developer Reference
    Range.Find Method
    Finds specific information in a range.
    Syntax

    expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)

    expression A variable that represents a Range object.

    Parameters

    Name Required/Optional Data Type Description
    What Required Variant The data to search for. Can be a string or any Microsoft Excel data type.
    After Optional Variant The cell after which you want the search to begin. This corresponds to the position of the active cell when a search is done from the user interface. Note that After must be a single cell in the range. Remember that the search begins after this cell; the specified cell isn’t searched until the method wraps back around to this cell. If you don’t specify this argument, the search starts after the cell in the upper-left corner of the range.
    LookIn Optional Variant The type of information.
    LookAt Optional Variant Can be one of the following XlLookAt constants: xlWhole or xlPart.
    SearchOrder Optional Variant Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns.
    SearchDirection Optional XlSearchDirection . The search direction.
    MatchCase Optional Variant True to make the search case sensitive. The default value is False.
    MatchByte Optional Variant Used only if you’ve selected or installed double-byte language support. True to have double-byte characters match only double-byte characters. False to have double-byte characters match their single-byte equivalents.
    SearchFormat Optional Variant The search format.

    Return Value
    A Range object that represents the first cell where that information is found.

    Remarks


    This method returns Nothing if no match is found. The Find method doesn’t affect the selection or the active cell.

    The settings for LookIn, LookAt, SearchOrder, and MatchByte are saved each time you use this method. If you don’t specify values for these arguments the next time you call the method, the saved values are used. Setting these arguments changes the settings in the Find dialog box, and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments. To avoid problems, set these arguments explicitly each time you use this method.

    You can use the FindNext and FindPrevious methods to repeat the search.

    When the search reaches the end of the specified search range, it wraps around to the beginning of the range. To stop a search when this wraparound occurs, save the address of the first found cell, and then test each successive found-cell address against this saved address.

    To find cells that match more complicated patterns, use a For Each...Next statement with the Like operator. For example, the following code searches for all cells in the range A1:C5 that use a font whose name starts with the letters Cour. When Microsoft Excel finds a match, it changes the font to Times New Roman.

    For Each c In [A1:C5] If c.Font.Name Like "Cour*" Then c.Font.Name = "Times New Roman" End If Next



    Example


    This example finds all cells in the range A1:A500 on worksheet one that contain the value 2 and changes it to 5.

    Visual Basic for Applications
    With Worksheets(1).Range("a1:a500")
    Set c = .Find(2, lookin:=xlValues)
    If Not c Is Nothing Then
    firstAddress = c.Address
    Do
    c.Value = 5
    Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
    End With

+ 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: 4
    Last Post: 06-21-2016, 06:38 AM
  2. Creating a list based on the results of an IF Statement
    By tcrjmom in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-06-2013, 07:16 PM
  3. Replies: 3
    Last Post: 12-06-2011, 05:47 PM
  4. Populating a list without blanks based on if statement
    By nicknick5219 in forum Excel General
    Replies: 3
    Last Post: 04-20-2009, 09:45 AM
  5. If Statement based on validation list
    By Ada01 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-12-2008, 03:10 PM
  6. List (based on if statement)
    By jermsalerms in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-08-2006, 12:53 PM
  7. a list, based on an IF statement
    By kaitewright in forum Excel General
    Replies: 1
    Last Post: 09-07-2006, 09:31 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