Wednesday 15 January 2014

excel - VBA Cutting string after last word less than 80 characters total length -


I am:

  • using the Excel clean function Touch all the formatting from any lesson, and
  • Then I want to break the resulting long string in separate lines of 80 characters or less.
  • After clearing, the only delimiter is a white space.

    The code below looks like a champion but it is cruel;

    Code

      sub-trimTo75 () myRow = 4 range ("C" and myRow). Select MyString = ActiveCell.Value while MyString & lt; & Gt; "" While Lane (MyString) & gt; 75 mySubString = Left (myString, 75) ActiveCell.Value = mySubString myString = Wright (Mystring, Lane (Mystring) - 75) myRow = myRow + 1 range ("C" and Marro) Select the application. Cut Copymode = Incorrect selection. Insert shift: = XLDown if lane (mestring) & lt; 75 then ActiveCell.Value = myString end if Wend myRow = myRow + 1 range ("C" and myRow). Select MyString = ActiveCell.Value Wend End Sub    

    Try it ..

      sub-trimTo75 () myRow = 4 range ("C" and "myRow"). MyString = ActiveCell.Value Dim x as myString & lt; & Gt; "Len (mestring)> = 75 x = 75 while not mid (mestring, x, 1) =" "x = x - 1 wend msbbox x 'mysbusting = left (mestring, 75) mysbusting = white (migrating, x) ActiveCell .Value = mySubString 'myString = Wright (Mystring, Lane (Maastrilling) - 75) Mystring = Mid (Maestring, X + 1) myRow = myRow + 1 range ("C" and Marro). Choose application .CutCopyMode = Incorrect selection. Instant shift: = XLDown if lane (mestring) <75 then ActiveCell.Value = myString equals If WRW = myRow + 1 range ("C" and myro) select MyString = ActiveCell.Value Wend End Sub    

No comments:

Post a Comment