VBA - Remove text between given 2 characters in string

sr1111

New Member
Joined
Sep 2, 2022
Messages
46
Office Version
  1. 2013
  2. 2011
  3. 2010
  4. 2007
Platform
  1. Windows
I am trying to copy all strings between 2 characters "; " and " . " in respective rows as in the below example.

25.xlsm
ABCD
1slInputoutput1output2
211 jones; smith. Lisa jones; festive discount. Lisa.; smith; festive discountjones. Lisa jones. Lisa.
3
4
52 jones; Light. Lisa jones; festive lucky discount 20p. Lisa. jones; Light. Lisa jones; festive lucky discount 20p. Lisa.; Light; festive lucky discount 20p; Light; festive lucky discount 20pjones. Lisa jones. Lisa. jones. Lisa jones. Lisa.
SheetA


I found the below vba from VBA - Remove text between given 2 characters in string
Sub RemoveDashToComma()
Columns("A:B").Replace ";*.", ",", xlPart
End Sub
I am looking for something very simple like this.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You say you want to copy all strings between "; " and " . " and that conforms to what you show as output1. But it does not explain output2.

You could potentially do output1 with a UDF.
VBA Code:
Function CustomExtract(ByVal CellTxt As String) As String
    Dim I As Long, S As String, SA As Variant
   
    SA = Split(Mid(CellTxt, InStr(CellTxt, ";") + 1, Len(CellTxt)), ";")
    For I = 0 To UBound(SA)
        S = S & Split(SA(I), ".")(0) & ";"
    Next I
    S = ";" & Left(S, Len(S) - 1)
    CustomExtract = S
End Function

Book1
ABC
1slInputoutput1
211 jones; smith. Lisa jones; festive discount. Lisa.; smith; festive discount
3
4
52 jones; Light. Lisa jones; festive lucky discount 20p. Lisa. jones; Light. Lisa jones; festive lucky discount 20p. Lisa.; Light; festive lucky discount 20p; Light; festive lucky discount 20p
Sheet1
Cell Formulas
RangeFormula
C2,C5C2=CustomExtract(B2)
 
Upvote 0
Output2 is the data in B without the data in C.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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