+ Reply to Thread
Results 1 to 3 of 3

Code to Assist with Nested Function, Also Using ISERROR

  1. #1
    Paige
    Guest

    Code to Assist with Nested Function, Also Using ISERROR

    My code has a function that equates to Lotus 123's XINDEX function; it works
    fine. I need to use the ISERROR with the formula in the cell that uses this
    function tho, so that when an error is returned, the cell shows blank; but
    when I add it, it goes over the 7 nested function limit. Note: This formula
    is in a cell that will also need to be copied and pasted down the column, so
    the formula references have to change (i.e., it is not a one cell thing that
    I could break up with a range name for example). The code for the XINDEX
    function is:

    Public Function xIndex(vRange, vRowVal, vColVal)
    On Error GoTo xIndexErr
    Application.Volatile
    With Application.WorksheetFunction
    xIndex = .Index(vRange, .Match(vColVal, vRange.Columns(1), 0),
    ..Match(vRowVal, vRange.Rows(1), 0))
    End With
    Exit Function
    xIndexErr:
    xIndex = CVErr(Err)
    End Function

    My formula is:
    =IF(P12=5,"",IF(M12=9,AU12,IF(M12=10,xINDEX(SMB,M12,H12),IF(M12<5,xINDEX(SNT,M12,H12),IF(M12<9,xINDEX(SNTOS,M12,H12),IF(M12<15,xINDEX(IPS,M12,H12),xINDEX(IPSOS,M12,H12)))))))
    The cell references in M and H will change as the formula is copied down the
    column; it also has range names (SMB, SNT, SNTOS, IPS, and IPSOS) that tell
    Excel where to look up the data.

    Is there a way to adjust the VB code for the function so that if the formula
    returns an error message, the cell shows blank? Or is there a better way to
    do this? Thanks for any thoughts/suggestions.

  2. #2
    Valued Forum Contributor Excelenator's Avatar
    Join Date
    07-25-2006
    Location
    Wantagh, NY
    Posts
    333
    According to your last question you could change the line after the "xIndexErr:" to read "xIndex = "" " or "xIndex = 0" . This will make the function return a blank or zero instead of an error message. I'm not sure if that will help or hurt your formula.


    Quote Originally Posted by Paige
    Public Function xIndex(vRange, vRowVal, vColVal)
    On Error GoTo xIndexErr
    Application.Volatile
    With Application.WorksheetFunction
    xIndex = .Index(vRange, .Match(vColVal, vRange.Columns(1), 0),
    ..Match(vRowVal, vRange.Rows(1), 0))
    End With
    Exit Function
    xIndexErr:
    xIndex = CVErr(Err)
    End Function

    .....

    Is there a way to adjust the VB code for the function so that if the formula
    returns an error message, the cell shows blank? Or is there a better way to
    do this? Thanks for any thoughts/suggestions.
    ---------------------------------------------------
    ONLY APPLIES TO VBA RESPONSES WHERE APPROPRIATE
    To insert code into the VBE (Visual Basic Editor)
    1. Copy the code.
    2. Open workbook to paste code into.
    3. Right click any worksheet tab, select View Code
    4. VBE (Visual Basic Editor) opens to that sheets object
    5. You may change to another sheets object or the This Workbook object by double clicking it in the Project window
    6. In the blank space below the word "General" paste the copied code.

  3. #3
    Paige
    Guest

    Re: Code to Assist with Nested Function, Also Using ISERROR

    Thanks; this might work - will give it a try!

    "Excelenator" wrote:

    >
    > According to your last question you could change the line after the
    > "xIndexErr:" to read "xIndex = "" " or "xIndex = 0" . This will make
    > the function return a blank or zero instead of an error message. I'm
    > not sure if that will help or hurt your formula.
    >
    >
    > Paige Wrote:
    > >
    > > Public Function xIndex(vRange, vRowVal, vColVal)
    > > On Error GoTo xIndexErr
    > > Application.Volatile
    > > With Application.WorksheetFunction
    > > xIndex = .Index(vRange, .Match(vColVal, vRange.Columns(1), 0),
    > > ..Match(vRowVal, vRange.Rows(1), 0))
    > > End With
    > > Exit Function
    > > xIndexErr:
    > > xIndex = CVErr(Err)
    > > End Function
    > >
    > > .....
    > >
    > > Is there a way to adjust the VB code for the function so that if the
    > > formula
    > > returns an error message, the cell shows blank? Or is there a better
    > > way to
    > > do this? Thanks for any thoughts/suggestions.

    >
    >
    > --
    > Excelenator
    >
    >
    > ------------------------------------------------------------------------
    > Excelenator's Profile: http://www.excelforum.com/member.php...o&userid=36768
    > View this thread: http://www.excelforum.com/showthread...hreadid=565399
    >
    >


+ 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.6.0 RC 1