Retrieve value in between parenthesis inside a cell

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
As the subject line states, I am wanting to retrieve the value between the open and closed parentheses. This is what I have so far. Thank you.

VBA Code:
Option Compare Text
Private Sub Workbook_Open()
    Dim cell As Range
    Dim str As String
    Dim n As Long

    For Each cell In Range("b2:b6")
        str = cell.Value
        n = InStr(str, "(")
        
        If n = 0 Then
            MsgBox "Character not found"
        Else
            cell.Select
            MsgBox "Character found in position: " & n
            MsgBox Left(str, n + 1)
        End If

    Next cell

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
is it just one set of parenthesis? Do you require a VBA solution, would a formula work?

Mr excel questions 39.xlsm
FG
22"A"="B",1,2
Sheet5
Cell Formulas
RangeFormula
F2F2=IF("A"="B",1,2)
G2G2=TEXTBEFORE(TEXTAFTER(FORMULATEXT(F2),"("),")")
 
Upvote 0
is it just one set of parenthesis?
@Pookiemeister
You did not address the above question, but assuming the answer to that is "yes", you could try this.

VBA Code:
Sub BetweenParentheses()
  Range("B2:B6").TextToColumns Range("C2"), xlDelimited, , , False, False, False, False, True, ")", Array(Array(1, 1), Array(2, 9))
  Range("C2:C6").TextToColumns , xlDelimited, , , False, False, False, False, True, "(", Array(Array(1, 9), Array(2, 1))
End Sub

Here is my sample data and the result of the above code.

Pookiemeister.xlsm
BC
1
2abc(def)ghidef
3
4Cost ($45.73)$45.73
5abcdef
6123456
Sheet1
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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