+ Reply to Thread
Results 1 to 11 of 11

Carriage returns (Enter) in a range

Hybrid View

  1. #1
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Carriage returns (Enter) in a range

    See how close this gets you
    Run from cell containing the text
    Amended text is dumped in adjacent cell to right
    Make sure receiving cell is a sensible width to prevent ridiculous row heights

    Sub Test()
        With ActiveCell
            .Offset(, 1).Value = CleanTrim(.Value)
        End With
    End Sub
    Function CleanTrim(ByVal s As String) As String
        Dim X As Long, CodesToClean As Variant
        s = Replace(s, Chr(13), Chr(10))
        s = Replace(s, Chr(160), Chr(32))
        s = Replace(s, Chr(10) & Chr(10), "|||")
        s = Replace(s, Chr(10), Chr(32))
        s = Replace(s, "|||", Chr(10))
        CleanTrim = WorksheetFunction.Trim(s)
    End Function
    (May need to insert an additional line break after a period and a colon etc)

    OR
    If you place above code in a general module, the function can be used in a normal Excel formula
    So with text in cell A1, and this formula in B1
    Formula: copy to clipboard
    =cleantrim(A1)
    Attached Files Attached Files
    Last edited by kev_; 02-07-2018 at 02:26 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Carriage Returns when concatenating
    By Wendy Collins in forum Excel General
    Replies: 2
    Last Post: 11-17-2011, 01:48 PM
  2. Carriage Returns
    By Highbury_White in forum Excel General
    Replies: 3
    Last Post: 02-24-2010, 10:09 AM
  3. How Do I Get Rid of Carriage Returns?
    By Ocean Zhang in forum Excel General
    Replies: 23
    Last Post: 07-02-2009, 10:49 AM
  4. Carriage returns in the formula bar?
    By rubeus in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-06-2006, 02:00 PM
  5. Delete Carriage Returns
    By Andre in forum Excel General
    Replies: 4
    Last Post: 12-01-2005, 07:35 PM
  6. Replies: 3
    Last Post: 11-17-2005, 03:10 PM
  7. VBA: Concatenate with carriage returns
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2005, 09:05 AM
  8. Carriage returns
    By tracyt620 in forum Excel General
    Replies: 1
    Last Post: 07-07-2005, 09:52 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1