+ Reply to Thread
Results 1 to 7 of 7

If Not IsError sometimes works...

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    339

    If Not IsError sometimes works...

    I have some code that only works sometimes and is not reliable.
    I don't know the exact syntax to use to make sure it will work all the time.

    I am basically checking the value in cell E107 and comparing it with a range of values in
    A20:A29 (named SYMB).

    This is the code I'm using:
    If Not IsError(Application.Match(Range("E107").Value, "SYMB", 0)) Then
    I have gone so far as formatting cell E107 to make sure the contents are in the same format as the contents in range SYMB. There are only text values in the range and E107.

    If anyone knows better code to use, I'd really appreciate knowing what it is.

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: If Not IsError sometimes works...

    try this:
    Public Sub test()
    Dim F_ound As Range
    Set F_ound = Range("SYMB").Find(What:="zxc", LookAt:=xlWhole)
    If Not F_ound Is Nothing Then
       MsgBox "FOUND"
    Else
       MsgBox "NOT FOUND"
    End If
    End Sub
    It looks at the whole content of the cells so it won't match partial word as "App" could match "Apple" or "Application"
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    339

    Re: If Not IsError sometimes works...

    Quote Originally Posted by p24leclerc View Post
    try this:
    Public Sub test()
    Dim F_ound As Range
    Set F_ound = Range("SYMB").Find(What:="zxc", LookAt:=xlWhole)
    If Not F_ound Is Nothing Then
       MsgBox "FOUND"
    Else
       MsgBox "NOT FOUND"
    End If
    End Sub
    It looks at the whole content of the cells so it won't match partial word as "App" could match "Apple" or "Application"
    Thanks for helping out!
    As I mentioned in my other reply, the Application.Match function won't work with my Excel version so it's a good thing your solution doesn't include it.

    I tested out your code with a couple of adjustments. Unfortunately neither worked.
    First I substituted What:="zxc" with What:="E107". E107 is the cell that contains the string I am comparing in the range named SYMB.
    Then I tried What:=E107
    Neither produced reliable results.

    I'm sure I need to make some simple adjustment.
    I'll give you a more concrete example, to show you what I'm trying to do.

    If cell E107 contains AAA, then I want to check range A20:A29, (which is named SYMB) and if there is an exact match, then DO This....
    It seems simple enough.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,953

    Re: If Not IsError sometimes works...

    Another suggestion:
    Option Explicit
    Sub test()
        Dim R
        On Error GoTo match_error:
        R = Application.Match(Range("E107").Value, Range("SYMB"), 0)
        MsgBox Range("E107").Value & " found at " & R
        Exit Sub
    match_error:
        Err.Clear
        MsgBox Range("E107").Value & " not found"
    End Sub
    Ben Van Johnson

  5. #5
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    339

    Re: If Not IsError sometimes works...

    Quote Originally Posted by protonLeah View Post
    Another suggestion:
    [CODE]Option Explicit
    Sub test()
    Dim R...
    Thanks proton, I'm trying out p24leclerc's code right now.

    Just before he posted it I discovered, much to my dismay, that my version of Excel (2002) does NOT have the Application.Match function. This is probably why it wasn't working for me.
    It allowed me to state the function, but it wouldn't work.

    I discovered this when I typed "Application. " and the list of functions came up.

  6. #6
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: If Not IsError sometimes works...

    here is themodification you are looking for:
    Set F_ound = Range("SYMB").Find(What:=Range("E107"), LookAt:=xlWhole)

  7. #7
    Forum Contributor
    Join Date
    02-14-2014
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2013
    Posts
    339

    Re: If Not IsError sometimes works...

    Quote Originally Posted by p24leclerc View Post
    here is themodification you are looking for:
    Set F_ound = Range("SYMB").Find(What:=Range("E107"), LookAt:=xlWhole)
    Merci beaucoup!
    I haven't tested it out thoroughly yet, but it seems to be working.
    I think it's the right modification.

+ 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. [SOLVED] Iserror works on one column but not two in small nested formula
    By Philb1 in forum Excel General
    Replies: 8
    Last Post: 07-07-2012, 02:08 AM
  2. Replies: 1
    Last Post: 12-15-2011, 08:43 PM
  3. How to Use IsError input if IsError=false
    By izpinoza in forum Excel General
    Replies: 1
    Last Post: 10-14-2009, 05:02 AM
  4. [SOLVED] Excel Addin works that works on a template workbook
    By s.jay_k in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-15-2006, 03:35 PM
  5. [SOLVED] How do I convert works file to excel without works software?
    By CatMB in forum Excel General
    Replies: 1
    Last Post: 06-21-2005, 12:05 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