Based on the code Zac gave me in
String length over 3 lines based on length
I now need to update to it to include the possibility that the text/words may not be separated by spaces but also the characters "/" or "_". I've had a good fiddle without success. I added if statements to the function such as :-
If InStr(55, sText, "_") > 0 Then
sGreater55 = Mid(sText, InStr(55, sText, "_"))
Without success :-(
Function SetString(ByVal sText As String) As String
Dim sGreater55$, sGreater19$
' If text is greater than 55 characters, first lets capture the string after 55 characters (depending on where the SPACE character is)
If Len(sText) > 55 Then
If InStr(55, sText, " ") > 0 Then
sGreater55 = Mid(sText, InStr(55, sText, " "))
Else
sGreater55 = Mid(sText, InStrRev(sText, " ", 55))
End If
End If
' If text is greater than 19 characters, lets build the string after 19 characters (depending on where the SPACE character is)
If Len(sText) > 19 Then
If InStr(19, sText, " ") > 0 Then
sGreater19 = Mid(sText, InStr(19, sText, " "))
Else
sGreater19 = Mid(sText, InStrRev(sText, " ", 19))
End If
sGreater19 = Left(sGreater19, Len(sGreater19) - Len(sGreater55))
End If
' Now lets build the complete string
SetString = Left(sText, Len(sText) - (Len(sGreater19) + Len(sGreater55))) & vbLf & sGreater19 & vbLf & sGreater55
End Function
Assuming that there might be an mixture of the split characters (Eg
blah_blah_blah blah_blah/blahblah
: Create a copy of your input string, replace all possible split characters by blank and slighly modify the function:Firstly Assumptions:
blah blah blah\blah\blah
)Based on the above assumptions, try this: