![]() |
|
#1
|
|||
|
|||
|
Hello,
I wonder if anyone may have a macro suggestion to selectively get rid of soft returns. For a number of reasons, I only want to get rid of soft returns in chunks of text so that the sentences are continuous (not segmented, like in the image attached). Essentially, I want to change the soft returns to blank spaces but only in the chunks of text. Any help would be greatly appreciated. |
|
#2
|
||||
|
||||
|
Your displayed screenshot suggests you're using Word, but you've posted in the Excel forum. Please clarify.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Hello,
Thank you for your reply. It is in Excel. I just posted the text through Word to show the soft returns. |
|
#4
|
||||
|
||||
|
I suspect you want to do something like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, j As Long, StrTmp As String
With Selection
For i = 1 To .Cells.Count
StrTmp = .Cells(i).Value
For j = Len(StrTmp) - 1 To 1 Step -1
If Mid(StrTmp, j, 1) = Chr(10) Then
If (Mid(StrTmp, j - 1, 1) <> Chr(10)) And (Mid(StrTmp, j + 1, 1) <> Chr(10)) Then
StrTmp = Left(StrTmp, j - 1) & " " & Right(StrTmp, Len(StrTmp) - j)
ElseIf (Mid(StrTmp, j + 1, 1) = Chr(10)) And (Mid(StrTmp, j + 2, 1) = Chr(10)) Then
StrTmp = Left(StrTmp, j - 1) & Right(StrTmp, Len(StrTmp) - j)
End If
End If
Next
.Cells(i).Value = StrTmp
Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
|
Thank you, so much!
I truly appreciate it. I'll try it and will let you know. Best regards. |
|
#6
|
|||
|
|||
|
Paul,
Thank you so very much! You are a magician. The macro works like a charm. |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Macro To Delete Specific Carriage Returns
|
NeviZero | Word VBA | 2 | 02-09-2018 02:16 PM |
Can't Get Centering right with soft return
|
Nathan8752 | Word | 10 | 11-19-2015 07:06 AM |
how to selectively highlight text in word
|
cnyoon2 | Word | 1 | 08-04-2015 08:16 AM |
| Need to Selectively Merge Records to Different Places in a Word Directory-type Document | TotheMoonAlice | Mail Merge | 3 | 03-27-2015 08:11 AM |
| How can I tag and selectively extract text (multiple files)? | PaulFitz | Word VBA | 12 | 10-31-2014 08:40 PM |