Find and Replace with formatting between two Characters

jcosman

New Member
Joined
Jan 8, 2019
Messages
2
Hi all,
I'm looking to find and replace with formatting between two characters. For Example: I want to find all instances of:

|Some Text| and replace it with Some Text.

Basically, it would remove the containing characters "I" and bold the text within these characters.

Any help would be greatly appreciated!

James
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
you just want to remove the first and last letter than bold it? or is it more complex than that? You can use Substitute formula =Substitute(Cell,"I","") and just bold the entire cell?
 
Upvote 0
Your post is a little confusing because your sample uses the pipe character |, but then you say replace I ??
 
Upvote 0
Assuming the delimiter is the pipe symbol (|), give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub BoldPipedText()
  Dim X As Long, PipeLeft As Long, PipeRight As Long, Arr As String, Cell As Range
  For Each Cell In Columns("A").SpecialCells(xlConstants)
    Do
      PipeRight = InStrRev(Cell.Value, "|")
      PipeLeft = InStrRev(Cell.Value, "|", PipeRight - 1)
      Cell.Characters(PipeLeft, PipeRight - PipeLeft + 1).Text = Cell.Characters(PipeLeft + 1, PipeRight - PipeLeft - 1).Text
      Cell.Characters(PipeLeft, PipeRight - PipeLeft - 1).Font.Bold = True
    Loop While InStrRev(Cell.Value, "|")
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Rick,

You can further improve your macro: it currently mishandles a non-between-pipes text in a cell ("ABCDEF" -- > "ABCDEFBCDEF") and throws an RTE 1004 for numbers.
 
Upvote 0
Thanks everybody. It is perhaps a little more complicated than what I wrote above which is why I was hoping a Find and Replace could solve. In reality, I may have a cell that looks like this:

|ABC Company|; Acme Company; |Some other Company|; Bill's Company;

And I would need to transform it to:

ABC Company; Acme Company; Some other Company; Bill's Company;
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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