Adding vbnewline into strings VBA

345 Views Asked by At

Ok when i was finally able to solve (with StackOverflow assistance) my arranging entries by time function, I was presented with a new issue.

It no longer followed the rules of the template i have attached to it. Not a huge problem because i thought of a quick solution but its not working.

I have added a function below, purpose:

  1. split the string passed to it -theSentence- into the array -theWords()-

  2. find out if the string -final- (do while loop adds each word from array to string one at a time) if more than 56 length

  3. if -final- is more than 56 length then add vbnewline to the string before adding next word

  4. change original string -theSentnce- to equal the created string -final- which should have a vbnewline in it after approx 56 length

.... not working need a push in the right direction probably something stupid

  Function chckLen(ByVal theSentence As String)

  Dim theWords() As String
Dim final As String
Dim arrayCntr As Integer
Dim arrayAmount As Integer
Dim chcker As Integer


 arrayCntr = 0

   theWords = Split(theSentence)
  arrayAmount = UBound(theWords)
  chcker = 56

  Do While arrayCntr <= arrayAmount

   If Len(final + theWords(arrayCntr)) > chcker Then
     final = final + vbNewLine
      final = final + theWords(arrayCntr)
     chcker = chcker + 56
   Else
     final = final + " " + theWords(arrayCntr)
   End If
         arrayCntr = arrayCntr + 1
  Loop

  theSentence = final

End Function
0

There are 0 best solutions below