Insert Line Break CHAR(10) Carriage return multiple times WITHIN a cell

EpicRadB

New Member
Joined
Jun 18, 2018
Messages
2
Hello All Excel Gurus out there,

I need help with designing VBA code to do the following:


[TABLE="width: 483"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Example[/TD]
[TD]Desired Outcome[/TD]
[/TR]
[TR]
[TD]*First Line*Second Line*Third Line[/TD]
[TD]*First Line
*Second Line
*Third Line[/TD]
[/TR]
[TR]
[TD]*First Line
*Second Line*Third Line[/TD]
[TD]*First Line
*Second Line
*Third Line

[/TD]
[/TR]
</tbody>[/TABLE]


Basically, all I want to do is look inside the cell for all the * except the first one and replace that with a line break and a "*"

I have over 15,000 cells with a variable number of "*" and I do not want to place a line break if one already exist before the "*".

Thanks in advance for any help.

I am new to the forum. What is the best way to paste a table into the message?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi & welcome to MrExcel.
I'm sure there must be a better way, but how about
Code:
Sub AddLF()
With Range("A1", Range("A" & Rows.Count).End(xlUp))
   .Replace "~*", Chr(10) & "*", xlPart
   .Replace Chr(10) & Chr(10), Chr(10), xlPart
   .Value = Evaluate(Replace("if(left(@,1)=char(10),right(@,len(@)-1),@)", "@", .Address))
End With
End Sub
 
Upvote 0
Here is another macro for you to consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub AddLFs()
  Dim Addr As String
  Addr = Range("A1", Cells(Rows.Count, "A").End(xlUp)).Address
  Range(Addr) = Evaluate("MID(SUBSTITUTE(SUBSTITUTE(" & Addr & ",CHAR(10),""""),""*"",CHAR(10)&""*""),2,999)")
  Range(Addr).EntireRow.AutoFit
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Cheers Rick
I new there must have been an easier way to do it :)
Just couldn't figure it out
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
I am actually trying to do the exact same thing as EpicRadB with an extract from an archaic database, but the above code is not working.

When I execute the macro all the cell over my range convert to a #VALUE! like there original reference has been deleted or something.

One other thing would the code above be able to put just one Char(10) after if there were multiple ***** consecutively ?
 
Upvote 0
Can you post some sample data?
There are some tools to help with that, if you follow the link in my signature
 
Upvote 0
Hi Fluff,

I went to link below your name, I don't have admin rights on the PC I can't install the tools being referenced;

SCHEDULING INSTRUCTIONS: * A * B *C *D *E *F

to #VALUE!

I wanted it to convert to:

*A
*B
*C
*D
*E
*F
 
Upvote 0
Using both codes here I get

SCHEDULING INSTRUCTIONS:
* A
* B
*C
*D
*E
*F
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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