Macro to split and wrap text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In column (D) I have a variable range of data where some cells have data
which includes a "|" character.

I need a macro which runs down col D - until the last populated row in Col E
- and if there is a cell with a "|" it deletes the character and wraps the
text as if I pressed Alt+Enter on the keyboard.

I would really appreciate some help with the code especially how I replicate
the Alt+Enter part of the process as I am totally stuck.

Many thanks in anticipation
 
this should get you started.

Sub ReplaceCharacters()
Dim rng As Range
Set rng = Cells(1, "D").Resize( _
Cells(Rows.Count, "E").End(xlUp).Row, 1)
rng.Replace What:="|", _
Replacement:=vbLf, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
rng.WrapText = True
rng.EntireColumn.AutoFit
End Sub

Obviously test it on a copy of your sheet since it changes data.
 
Back
Top