How to remove Parenthesis with numbers and text without removing the remaining text after

Dith2228

New Member
Joined
Jul 1, 2022
Messages
14
Office Version
  1. 365
Platform
  1. Windows
I have been trying to find answer on how to remove a parenthesis with number and text inside withou the remaining words after being removed. In example

I have reviewed T09_535 (243 pages), N4057.005 (3 documents).

Result must be

I have reviewed T09_535, N4057.005.

I have tried the Find and Replace using find (*pages) and replces with space but it did not worked. Please help
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try

Find: (*) Note: Before ( put a space
Replace:

1728432177643.png
 
Upvote 0
Try
Code:
Sub Del_Brackets_And_In_Between()
    Dim Text As String
    Dim StartPos As Long
    Dim EndPos As Long
    Dim c As Range, i As Long
    Application.ScreenUpdating = False
    For Each c In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
    For i = 1 To Len(c.Value) - Len(Replace(c.Value, "(", ""))
        Text = c.Value
        StartPos = InStr(Text, "(")
        EndPos = InStr(Text, ")")
            c.Value = Left(Text, StartPos - 1) & Mid(Text, EndPos + 1)
    Next i
    Next c
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
1) Formula
=REGEXREPLACE(A1," *\(.+?\) *","")

2) vba(udf)
Use like in cell
=RemoveBetween(A1," (",")")
Code:
Function RemoveBetween(ByVal txt$, s1$, s2$) As String
    Dim x&, y&
    x = InStr(txt, s1)
    Do While x
        If Mid$(txt, x) Like " ([!" & Trim$(s1) & "]*" & s2 & "*" Then
            y = InStr(x, txt, ")")
            Mid$(txt, x) = String(y - x + 1, Chr(2))
        End If
        x = InStr(x + 1, txt, s1)
    Loop
    RemoveBetween = Application.Trim(Replace(txt, Chr(2), ""))
 End Function
3) You can call udf from the sub procedure, if you want to remove from the source data.
Code:
Sub test()
    Dim a, i&
    With Range("a1", Range("a" & Rows.Count).End(xlUp))
        a = .Value
        For i = 1 To UBound(a, 1)
            a(i, 1) = RemoveBetween(a(i, 1), " (", ")")
        Next
        .Value = a
    End With
End Sub
 
Upvote 0
One example is not much to go on, but this is my best guess.
I have put results in the next column but if this does what you want you can remove the .Offset(, 1) from the line near the end.
If none of the suggestions are what you want, please give 10-15 varied samples of data and the expected results

VBA Code:
Sub RemoveSomeParentheses()
  Dim RX As Object
  Dim a As Variant
  Dim i As Long
  
  Set RX = CreateObject("VBScript.RegExp")
  RX.Global = True
  RX.Pattern = " *\(\d+ *(page|document)[^\)]*\)"
  With Range("a2", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    For i = 1 To UBound(a)
      a(i, 1) = Application.Trim(RX.Replace(a(i, 1), ""))
    Next i
    .Offset(, 1).Value = a
  End With

Dith2228.xlsm
AB
1Sample DateCode results
2I have reviewed T09_535 (243 pages), N4057.005 (3 documents)I have reviewed T09_535, N4057.005
3Tom reviewed nothing (he's lazy), as usualTom reviewed nothing (he's lazy), as usual
4Ken read a book (30 chapters), watched tv (movie) & ate grapes (10 of them)Ken read a book (30 chapters), watched tv (movie) & ate grapes (10 of them)
5(10 pages and) some text (1 document)some text
6(no number and) some text(no number and) some text
7What about (2 pages) (or 3 together)What about (or 3 together)
Sheet1
 
Upvote 0
Code:
Sub Or_So()
 Columns(1).Replace " (*)", ""
End Sub

Does not work for your requirement of Post #3
 
Upvote 0
If you don't want to use code give this a try in Find What box.
Rich (BB code):
(*? pages)
 
Upvote 0
One example is not much to go on, but this is my best guess.
I have put results in the next column but if this does what you want you can remove the .Offset(, 1) from the line near the end.
If none of the suggestions are what you want, please give 10-15 varied samples of data and the expected results

VBA Code:
Sub RemoveSomeParentheses()
  Dim RX As Object
  Dim a As Variant
  Dim i As Long
 
  Set RX = CreateObject("VBScript.RegExp")
  RX.Global = True
  RX.Pattern = " *\(\d+ *(page|document)[^\)]*\)"
  With Range("a2", Range("A" & Rows.Count).End(xlUp))
    a = .Value
    For i = 1 To UBound(a)
      a(i, 1) = Application.Trim(RX.Replace(a(i, 1), ""))
    Next i
    .Offset(, 1).Value = a
  End With

Dith2228.xlsm
AB
1Sample DateCode results
2I have reviewed T09_535 (243 pages), N4057.005 (3 documents)I have reviewed T09_535, N4057.005
3Tom reviewed nothing (he's lazy), as usualTom reviewed nothing (he's lazy), as usual
4Ken read a book (30 chapters), watched tv (movie) & ate grapes (10 of them)Ken read a book (30 chapters), watched tv (movie) & ate grapes (10 of them)
5(10 pages and) some text (1 document)some text
6(no number and) some text(no number and) some text
7What about (2 pages) (or 3 together)What about (or 3 together)
Sheet1
This is fantastic. How do i change the condition say if my cell contains (9:30am to 2:30pm) within the parenthesis but the time varies and i also need to remove that parenthesis with time inside? super thank you for your help.
 
Upvote 0

Forum statistics

Threads
1,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

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