Consulting

Results 1 to 5 of 5

Thread: Solved: Need a Function or Vlookup to replace Nested If

  1. #1
    VBAX Regular
    Joined
    Oct 2008
    Posts
    69
    Location

    Solved: Need a Function or Vlookup to replace Nested If

    My nested "If" has far too many variables to work (far exceeds the alloted 7)...and I am not sure this does everything anyway...

    =IF(ISBLANK(B14),"",IF(B5=AA1,OR(B5=AA2,OR(B5=AA3,IF(B50>=1.67,AB8,IF(B50>= 133,AB9,IF(B50<1.33,AB10,if(b5=AA4,or(b5=aa5,if(b50=>1.33,AB8,if(b50=>1.00, K38,if(b50<1.00,AB10,AB11)))))))

    I have 5 rannkings (S, R, A, B, and C) and 3 possible results in each option.


    B5 is cell where user chooses the rank from a dropdown

    AA1 = S
    AA2 = R
    AA3 = A
    AA4 = B
    AA5 = C

    AB8 = Approved
    AB9 = SPC must be used to control the process
    AB10 = 100% Inspection Required
    AB11 = Not Approved


    What I have is a process capability spreadsheet.
    The ranking are "special characteristic rankings and the results are Cpk numbers.

    If the rank is S, R, or A, and the Cpk is >1.67 process is approved;
    If the Cpk is between 1.67 and 1.33 the process must use SPC to control the process;
    If the Cpk is <1.33 100% inspection must be used

    If the ranks are B or C and the Cpk is >1.33 process is approved;
    If the Cpk is between 1.33 and 1.00 the process must use SPC to control the process;
    If the Cpk is <1.00 100% inspection must be used.

    What is the best way to get this done?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try

    =IF(ISBLANK(B14),AB11,
    IF(OR(B5=AA1,B5=AA2,B5=AA3),IF(B50>=1.67,AB8,IF(B50>=133,AB9,AB10)),
    IF(OR(B5=AA4,B5=AA5),IF(B50>=1.33,AB8,IF(B50>=1,AB9,AB10)))))
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Oct 2008
    Posts
    69
    Location
    xld...too many "Ifs"

    Here is what I ended up using:

     
    Function RankCpk(sRank As Range, cpk As Range) As String
        Select Case UCase(sRank)
            Case "S", "R", "A"
                If cpk < 1.33 Then
                    RankCpk = "100% Inspection Required"
                ElseIf cpk <= 1.33 Then
                    RankCpk = "SPC must be used to control the process"
                ElseIf cpk >= 1.67 Then
                    RankCpk = "Approved"
                End If
            Case "B", "C"
                If cpk < 1# Then
                    RankCpk = "100% Inspection required"
                ElseIf cpk < 1.33 Then
                    RankCpk = "SPC must be used to control the process"
                ElseIf cpk >= 1.33 Then
                    RankCpk = "Approved"
                End If
            Case Else
                RankCpk = "Char. Rank Not Specified"
        End Select
    End Function

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    What about Case A, cpk = 1.5?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by GoKats78
    xld...too many "Ifs"

    Here is what I ended up using:

     
    Function RankCpk(sRank As Range, cpk As Range) As String
        Select Case UCase(sRank)
            Case "S", "R", "A"
                If cpk < 1.33 Then
                    RankCpk = "100% Inspection Required"
                ElseIf cpk <= 1.33 Then
                    RankCpk = "SPC must be used to control the process"
                ElseIf cpk >= 1.67 Then
                    RankCpk = "Approved"
                End If
            Case "B", "C"
                If cpk < 1# Then
                    RankCpk = "100% Inspection required"
                ElseIf cpk < 1.33 Then
                    RankCpk = "SPC must be used to control the process"
                ElseIf cpk >= 1.33 Then
                    RankCpk = "Approved"
                End If
            Case Else
                RankCpk = "Char. Rank Not Specified"
        End Select
    End Function
    You jest surely? You can have 7 nested, that only as 6.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •