VBA for text string replacement

Berek

New Member
Joined
Apr 11, 2012
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I'd like to run VBA that will perform these steps

1) Remove the Letter at the beginning of each line

2) Remove any comma that comes after a bracket

3) Replace the brackets with a forward slash

The strings would vary in length.

Thanks
Berek

Mr Excel string formula.xlsx
DEFGHI
5Original Text StringWhat it needs to look like
6T(1),(3,4),(3,4,6,7,10)1/3,4/3,4,6,7,10/
7T(1),(3,4,5,8),(3,4,5,8)1/3,4,5,8/3,4,5,8/
8T(6),(3,4,7,11,15),(3,4,7,11,15)6/3,4,7,11,15/3,4,7,11,15/
Sheet1
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Does it need to be VBA?

Book1
ABCDEFG
1Original Text StringWhat it needs to look like
2T(1),(3,4),(3,4,6,7,10)1/3,4/3,4,6,7,10/1/3,4/3,4,6,7,10/TRUE
3T(1),(3,4,5,8),(3,4,5,8)1/3,4,5,8/3,4,5,8/1/3,4,5,8/3,4,5,8/TRUE
4T(6),(3,4,7,11,15),(3,4,7,11,15)6/3,4,7,11,15/3,4,7,11,15/6/3,4,7,11,15/3,4,7,11,15/TRUE
Sheet7
Cell Formulas
RangeFormula
F2:F4F2=LET(r,RIGHT(A2,LEN(A2)-1),p,SUBSTITUTE(r,")","/"),l,SUBSTITUTE(p,"(",""),SUBSTITUTE(l,"/,","/"))
G2:G4G2=D2=F2
 
Upvote 0
Here's a macro:

VBA Code:
Sub Test1()

    Set r = Range(Range("D6"), Range("D6").End(xlDown))
    r.Value = Evaluate("=IF(1,SUBSTITUTE(SUBSTITUTE(MID(" & r.Address & ",3,999),""),("",""/""),"")"",""/""),"""")")
    
End Sub

It's based on a formula too:

Excel Formula:
=SUBSTITUTE(SUBSTITUTE(MID(D6,3,999),"),(","/"),")","/")
 
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,329
Members
451,637
Latest member
hvp2262

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