Change Text Case But ONLY Within (****) Brackets

KennyUK

New Member
Joined
Apr 4, 2003
Messages
6
Hi Guys,

I have a bit of a problem that I wondered if anyone can help me with.

I need to be able to change the case of text contained inside brackets to Sentence Case (Each Word Starts With A Capital Letter. I need it to ignore any text before or after the ( ). It would be best for me if this could be used as a macro or addin.

Here is an example of what I need:

Cell A1 = Hello There (how are you today)
Cell A2 = The (sun) is hot

Want to change to:

Cell A1 = Hello There (How Are You Today)
Cell A2 = The (Sun) is hot

Any ideas or suggestions would be gratefully accepted.

My thanks in advance,

Kenny
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi Kenny,

How about:
Code:
Sub ISentenceYou()
    Dim rngText As Range, rngCell As Range
    Dim lStart As Long, lEnd As Long, strTemp As String
    
    Application.ScreenUpdating = False
    
    With ThisWorkbook.Worksheets("Sheet1")
        Set rngText = .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row) _
            .SpecialCells(xlCellTypeConstants, xlTextValues)
        For Each rngCell In rngText
            lStart = 0: lEnd = 0
            With rngCell
                lStart = InStr(1, .Text, "(")
                If lStart > 0 Then
                    lEnd = InStr(lStart, .Text, ")")
                    If lEnd > 0 Then
                        strTemp = Left(.Text, lStart) & _
                            Application.WorksheetFunction.Proper _
                            (Mid(.Text, lStart + 1, lEnd - (lStart + 1))) & _
                            Right(.Text, Len(.Text) - (lEnd - 1))
                        .Value = strTemp
                    End If
                End If
            End With
        Next rngCell
    End With
    
    Application.ScreenUpdating = True
    
End Sub
You could amend the range definition to use Selection if you wanted something more general-purpose.

HTH
 

Krishnakumar

Well-known Member
Joined
Feb 28, 2003
Messages
2,615
Hi,

A formula based approach.

=LEFT(A1,FIND("(",A1)-1)&(PROPER(MID(A1,FIND("(",A1),(FIND(")",A1)-FIND("(",A1)+1)))&RIGHT(A1,LEN(A1)-FIND(")",A1)))
 

Forum statistics

Threads
1,181,751
Messages
5,931,807
Members
436,805
Latest member
waseem abbas

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
Top