I am trying to build a Excel function in VBA using the Replace function The function I build checks if the length of the text is bigger then a defined value by the user as long as it is bigger it goes through a series of if's.
However it seems that only the first condition for replacing text is working.
If you look at the example spreadsheet I attached to this question.
That column "a" has the original text and column "b" the substitute text
For an example in b2 the word "bin" is replaced with "no bin" however the other condition that replaces the word "blue" with "no blue".Seems not to be working.
What am I doing wrong?
Here is the code I am using
Function title_trim(title, length) As StringPlease Login or Register to view this content.
If Len(title) > length Then
title = Replace(title, "bin", "no bin")
ElseIf Len(title) > length Then
title = Replace(title, "blue", "no blue")
ElseIf Len(title) > length Then
title = Replace(title, "greem", "no green")
ElseIf Len(title) > length Then
title = Replace(title, "pink", "")
End If
title_trim = title
End Function
Please Login or Register to view this content.
Bookmarks