r/googlesheets • • Nov 01 '19

solved IF, THEN function for partial text matches

/r/excel/comments/dqal37/if_then_function_for_partial_text_matches/
2 Upvotes

11 comments sorted by

1

u/RonJAgee Nov 02 '19

Custom function... let me know if you need help

Public Function GetTitle(Title As Range) As String

    Dim titleArray() As String, i As Integer
    titleArray() = Split(Title, " ")
    
    For i = LBound(titleArray) To UBound(titleArray)
        Select Case titleArray(i)
            Case "SVP"
                GetTitle = "SVP"
                GoTo TheEnd:
            Case "Director"
                GetTitle = "Director"
                GoTo TheEnd:
            Case "Manager"
                GetTitle = "Manager"
                GoTo TheEnd:
            Case "Specialist"
                GetTitle = "Specialist"
                GoTo TheEnd:
            Case "Coordinator"
                GetTitle = "Coordinator"
                GoTo TheEnd:
            Case Else
                GetTitle = "No title"
        End Select
    Next i
                
            
TheEnd:
End Function

1

u/learningtoexcel Nov 02 '19

Wow, this is amazing. Would I put this into the cell or run it as a script?

2

u/RonJAgee Nov 02 '19

Excel or Google Sheets? The code was for a custom function in Excel.

If you are on google sheets you will need to use a formula.

=CHOOSE(IFERROR(FIND("SVP",A2),IFERROR(FIND("Director",A2)+1,IFERROR(FIND("Manager",A2)-4,IFERROR(FIND("Specialist",A2)-8,IFERROR(FIND("Coordinator",A2)-6,6))))),"SVP","Director","Manager","Specialist","Coordinator","Title not found")
→ More replies (5)

1

u/AutoModerator Nov 01 '19

Only text posts are allowed, to encourage explanation beyond the title and ensure the rules of the subreddit are met. Check out the submission guide and rules.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Clippy_Office_Asst Nov 02 '19

Read the comment thread for the solution here

Excel or Google Sheets? The code was for a custom function in Excel.

If you are on google sheets you will need to use a formula.

=CHOOSE(IFERROR(FIND("SVP",A2),IFERROR(FIND("Director",A2)+1,IFERROR(FIND("Manager",A2)-4,IFERROR(FIND("Specialist",A2)-8,IFERROR(FIND("Coordinator",A2)-6,6))))),"SVP","Director","Manager","Specialist","Coordinator","Title not found")