+ Reply to Thread
Results 1 to 4 of 4

Using IFERROR in VBA

  1. #1
    Registered User
    Join Date
    10-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Using IFERROR in VBA

    Im having problems taking a formula that works in excel and making it work in VBA. I have a column of text as follows

    `1-1
    `1-2
    `1-3
    `1-4
    100
    101
    ALL
    `22-2
    `22-20

    I would like to pull out the numbers to the right of the the dash when the entries are in that format but let the value pass through if it something other than the dashed format.

    =IFERROR(MID(F1,(FIND("-",F1)+1),2),F1) works very nicely in excel to do what I want but Ive tried everything I know to do (and that's not much, this is the second program Ive ever written) to make it work in VBA


    Here is what Ive come up with and it is not working

    Please Login or Register  to view this content.
    I appreciate any help that anyone can give me on this

    thanks


    Edit

    I figure out what I was doing wrong

    Please Login or Register  to view this content.
    Last edited by kirk70; 11-02-2013 at 11:15 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Using IFERROR in VBA

    Try this. In VBA when you use WorksheetFunction, it is not simply a copy of the actual worksheet function. It is a VBA Function with parameters, and the parameters must be VBA expressions. In VBA, using F1 unadorned like that means it's an undeclared variable. It will cause a compile error if you use Option Explicit, and otherwise will just be a Variant variable that hasn't been assigned a value. You have to use an expression that results in a Range.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Using IFERROR in VBA

    Thanks 6 string. It is now objecting the "find" function. Do I need to have another reference to the worksheet function before using "find"

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Using IFERROR in VBA

    Yes, you do. Sorry I didn't pick that up the first time around. Alternatively you could use the VBA built-in function InStr which does just about the same thing without using a worksheet function.

+ 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. xlfn.IFERROR or IFERROR don't work in Excel 98-2003
    By dj_danu01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2013, 02:53 AM
  2. [SOLVED] no IFERROR
    By DBenson1968 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-26-2013, 03:52 PM
  3. [SOLVED] Sum+IFERROR Help
    By chriswiec in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-27-2013, 09:43 AM
  4. [SOLVED] Iferror
    By Notters in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-04-2013, 12:34 PM
  5. If? Iferror?
    By amthyst826 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-22-2010, 08:06 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