Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello all!
I am writing a function to format text to be displayed in a MsgBox. So far it works, however, it will cut off the last word in the last line if the text is over 45 characters - and error out if there are no spaces in the last line. - ie the text is 50 characters long and the 'remainder' is the word "end.") (Thanks to Tom O. for the base of this code) what am i missing? <BEGIN VBA CODE Public Function formatString(str As String) If Len(str) <= 45 Then formatString = str Else Dim temp As String formatString = "" For j = 0 To CInt(Application.WorksheetFunction.RoundDown(Len(s tr) / 45, 0)) temp = Left(str, 45) i = 45 Do While Mid(temp, i, 1) < " " And i 1 i = i - 1 Loop formatString = formatString + Mid(temp, 1, i) + Chr(13) str = Mid(str, i + 1) Next j End If End Function <END VBA CODE |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Formatting Text in cells that already have text entered | Excel Worksheet Functions | |||
copying text within a text box and losing formatting | Excel Discussion (Misc queries) | |||
Formula Text String: Formatting Text and Numbers? | Excel Discussion (Misc queries) | |||
Conditional Formatting based on text within a cell w/ text AND num | Excel Worksheet Functions | |||
Conditional Formatting based on Text within Text | Excel Discussion (Misc queries) |