Find & Replace Line Break

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
Hopefully an easy one this.

I would like to find and replace all line breaks within each cell in column K of my data, with a space instead.

I do this with some other characters, but am unsure how to do this with a line break. I can do this manually using the replace tool and then using either Ctrl+J or ALT 010 to type a line break, but am unsure how to do this in VBA.

For reference here is my similar code to replace all "&" with "and"

Code:
With ws1.Range("K2:K" & lngLastRow)    Set c = .find("&", LookIn:=xlValues)
    If Not c Is Nothing Then
        firstAddress = c.Address
        Do
            c.Value = Replace(c.Value, "&", "and")
            Set c = .FindNext(c)
        Loop While Not c Is Nothing
    End If
End With
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi, you could try with out looping something like this:

Code:
With ws1.Range("K2:K" & lngLastRow)
    .Replace What:=Chr(10), Replacement:=" ", LookAt:=xlPart
    .Replace What:="&", Replacement:="and", LookAt:=xlPart
End With
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top