Results 1 to 6 of 6

Thread: Remove Hard Carriage Return And Leading And Trailing Spaces

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    3
    Rep Power
    0

    Remove Hard Carriage Return And Leading And Trailing Spaces

    Mr. Rick,

    Looking for a solution to my situation, I have found this 2013 post: https://www.mrexcel.com/forum/excel-...e-returns.html. I have tried to post my question here but it seems to be old and required to have a new post.

    Your solution works great from me to remove hard carriage returns. I would like to see if possible to incorporate this to an existing private sub I am using to trim spaces from start and end of entered text strings.

    My code is the following:

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
      Dim Cell As Range
      If Not Intersect(Target, Range("A4:A1004")) Is Nothing Then
        Application.EnableEvents = False
        For Each Cell In Intersect(Target, Range("A4:A1004"))
          If Len(Cell.Value) Then Cell.Value = Trim(Cell.Value)
        Next
        Application.EnableEvents = True
      End If
    End Sub
    I would like to include your solution to above mentioned, so that when entering information at the target range, the macro automatically removed the hard carriage returns as well

    Code:
    Sub ReplaceAtSignWithLineFeed_v3()
      Selection = Evaluate("IF(ROW(),SUBSTITUTE(" & Selection.Address & ",CHAR(10),""""))")
    End Sub
    By the way, my first macro portion takes some time to execute, if you can suggest a more effective and expedited way to do it, please let me know.

    Thanks in advance for your assistance.
    Last edited by Excel Fox; 04-08-2019 at 10:13 PM. Reason: Code Tags Added

Similar Threads

  1. Wrap Text On Spaces Up To A Maximum Number Of Characters Per Line
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 15
    Last Post: 12-20-2016, 09:47 AM
  2. hard question
    By mahmoud-lee in forum Excel Help
    Replies: 1
    Last Post: 05-28-2013, 02:27 PM
  3. LTRIM() Function VBA: To Remove Spaces
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 05-17-2013, 12:32 AM
  4. Macro to delete trailing X's
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 03-29-2013, 12:43 PM
  5. VBA editor auto-deletes spaces at the ends of lines
    By LalitPandey87 in forum Excel Help
    Replies: 0
    Last Post: 06-26-2012, 07:53 PM

Tags for this Thread

Posting Permissions

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