+ Reply to Thread
Results 1 to 5 of 5

Remove multiple Carriage Returns - macro to clean cell contents

  1. #1
    Registered User
    Join Date
    02-26-2014
    Location
    Salt Lake City
    MS-Off Ver
    Excel 2010
    Posts
    3

    Remove multiple Carriage Returns - macro to clean cell contents

    Hello, this is my first post to this forum.

    I found a macro that cleans the text the way I would like it to show up in the cells that have multiple CR's in them.
    I want to keep the CR at the end of a line of text, but if there is a CR and no text I want to remove that CR.

    As I tested this macro, I found that it will only update Cells in column A, and will only run when there is an entry in column C only. If there are no entries in column C it will not run (no cleaning done in column A)

    Also, it will only clean column A on rows that are on, or above, the row that has an entry in column C.

    I would like, and have not figured out how , it to clean a specific column of data, the column could have 5 to 100 rows in it. Also, it makes one pass and I will need it to make up to 5 passes to remove all of the potential CR's.

    This is the Macro:

    Please Login or Register  to view this content.
    Thanks is advance, and I hope I have posted this correctly.
    ~Lloyd
    Last edited by Fotis1991; 02-28-2014 at 11:13 AM. Reason: Pls use code tags around your codes...

  2. #2
    Registered User
    Join Date
    02-26-2014
    Location
    Salt Lake City
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Remove multiple Carriage Returns - macro to clean cell contents

    I have been doing a lot of searching and found a macro that got me very close to my needs.

    For this one, I have to select the cell, or cells manually and it puts the cleaned up text the way I like to see it.
    I have tried to figure out how to define a specific range Column P, Rows 15 to 100 - but I am struggling with the code.

    Here is the closer solution, if someone can help...

    Sub test()
    Dim r As Range
    With CreateObject("VBScript.RegExp")
    .Global = True
    For Each r In Selection
    .Pattern = "\n+(\s+)"
    r.Value = .Replace(r.Value, vbLf & vbLf)
    Next
    End With
    End Sub

    Thanks...
    ~Lloyd

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Remove multiple Carriage Returns - macro to clean cell contents

    Lloyd,
    Welcome to the forum!
    Please take moment to read forum's rules.
    You need to use code tags with your code.

    You can have a fixed range or dynamic one.
    Please Login or Register  to view this content.
    Or you could use this line which selects from P15 down until the last row on column P
    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Remove multiple Carriage Returns - macro to clean cell contents

    Please Login or Register  to view this content.
    This doesn't make sense to me.

    Can you show me what you have and the result that you want?

  5. #5
    Registered User
    Join Date
    02-26-2014
    Location
    Salt Lake City
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Remove multiple Carriage Returns - macro to clean cell contents

    AB33,

    Your help is greatly appreciated. I used the fixed range solution you provided, and I will keep the dynamic solution noted for future work.
    Thanks again...

+ 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. Remove Carriage Returns From Target Cell
    By JoJo in forum Excel General
    Replies: 1
    Last Post: 03-22-2007, 05:23 PM
  2. Can you use the Replace function to remove carriage returns?
    By iterature in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-12-2007, 08:45 AM
  3. How do you programically remove carriage returns within a cell
    By Lee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2005, 04:05 PM
  4. [SOLVED] how do I remove Carriage Returns from a column in a spreadsheet?
    By Doug R in forum Excel General
    Replies: 1
    Last Post: 06-29-2005, 04:05 PM
  5. Replies: 4
    Last Post: 02-18-2005, 08:06 PM

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