+ Reply to Thread
Results 1 to 2 of 2

Thread: iferror in macro

  1. #1
    Registered User
    Join Date
    02-02-2012
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2011
    Posts
    13

    iferror in macro

    I have a macro where I'm trying to find the position of "E" or "H" in a variable length string, Bookname. Bookname has either an E or an H but not both. I tried using an IF statement

    EHPosition = if(iserror(instr(Bookname,"E")=TRUE, EHPosition = instr(Bookname,"H"), _ 
    EHPosition = instr(Bookname,"E"))
    but I get "Expected Expression" on the IF.

    I then tried
     EHPosition = IfError(InStr(BookName, "E"), InStr(BookName, "H"))
    but I get "Sub or Function Not Defined" for the IfError.

    What to do?

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    MSO2007 on WinXP/MSO2000 on Win7/winXP
    Posts
    2,180

    Re: iferror in macro

    Insr() returns 0 if not found, therefore:
    EHPosition = InStr(BookName, "H")
    If EHPosition = 0 Then
        EHPosition = InStr(BookName, "E")
    End If
    
    ---
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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.2.0