Pro VBA help needed getting rid of " | " in a string of data

peter_z

Board Regular
Joined
Feb 27, 2011
Messages
87
Hey guys, I have a string of text in a single cell.

name: peter z | name: john h| name: john g| Age: 22

I have some code which seperates the pipes from the cell and then puts it into seperate columns.

Problem: The string Name: John g Age: 22 needs to be together not seperated.

Does anyone have any code that possibly looks at Age and gets rid of the | just before the A ?

Alternatively any suggestions on how I can fix this problem?

Your help is much appreciated!

Thanks :)
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi Peter
Before running your seperate code, Highlight your cells and run this to remove the pipes first.
Code:
Sub rempipe()
Dim c As Range
For Each c In Selection
    c.Value = Replace(c.Value, "|", " ")
Next c
End Sub
 
Upvote 0
Code:
[COLOR="Blue"]Function[/COLOR] RemSep(Str [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]) [COLOR="Blue"]As[/COLOR] [COLOR="Blue"]String[/COLOR]
    [COLOR="Blue"]With[/COLOR] CreateObject("VBScript.RegExp")
        .Pattern = "\|\s*Age"
        RemSep = .Replace(Str, " Age")
    [COLOR="Blue"]End[/COLOR] [COLOR="Blue"]With[/COLOR]
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Function[/COLOR]
 
Upvote 0
Hey Guys, thanks a lot for your time and help :)
I'm going to fiddle around with the function formula it looks like it will do pretty much what I am looking for.

- Peter
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,242
Members
452,898
Latest member
Capolavoro009

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