1

I have a column of values for universities. For example, I have a column with string "University of Michigan" and "UMich"

why won't the following function return back in the cell a string "University of Michigan"

Function CleanUniCode(entry) As Variant
If entry = "UMich" Then entry = "University of Michigan"

End Function

Also tried this and the cell is returning 0, not sure why.

Function CleanUniCode(entry) As Variant
If entry Like "[UMich]" Then
entry = "University of Michigan"
ElseIf entry Like "[UPenn]" Then
entry = "University of Pennsylvania"
Else:
End If

End Function

1 Answer 1

5

It's because you assigned the return value to entry, but you should assign it to CleanUniCode:

Function CleanUniCode(entry) As Variant
    If entry = "UMich" Then CleanUniCode = "University of Michigan"
End Function

Always assign the return value to the function name.

Sign up to request clarification or add additional context in comments.

4 Comments

Question: Why doesn't the following work? It gives me a value error in return, If entry = "UMich" or "Umich" Then CleanUniCode = "University of Michigan"
Because you must have entry = ... for each piece of the OR statement: If entry = "UMich" or entry = "Umich" Then CleanUniCode = "University of Michigan"
how could I code so that if the function encounters another school, say "Harvard", the function just passes it over and leaves it as is
In that case, change the CleanUniCode = "University of Michigan" back to entry = "University of Michigan" and then before End Function add the line: CleanUniCode = entry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.