+ Reply to Thread
Results 1 to 2 of 2

Capitalize words within parentheses

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2013
    Location
    Tallahassee
    MS-Off Ver
    Excel 2010
    Posts
    30

    Capitalize words within parentheses

    I am using Excel 2010.

    In a spreadsheet I have to change text in various places to proper case. I have some exceptions such as the word 'of'. All this works.

    Is there any way for me to capitalize words around parentheses. Any word wrapped in parentheses is a government acronym and should be capitalized. Currently after running this macro, (FDA) comes out as (Fda).

    Thank you for your help.

    --Perry


    Sub mcrzzProperCaseTEST2()
    'Proper Case selected cells with Exceptions for Prepositions
    'Subordinate conjuctions will be capitalized -- because, as, who, if, that, what, why, that, when, where
    
    'Following will be in lower case:
    a, an, the, and, but, for, nor, yet, by, with, on, to, of, at, around
    
    Dim txtString As String
    Dim RngCell As Range
    
    'Do not convert exceptions in cells selected to proper case
    For Each RngCell In Selection
    
        txtString = Application.WorksheetFunction.Proper(RngCell.Value)
        txtString = Application.Substitute(txtString, " Of ", " of ")
        RngCell.Value = txtString
    
    Next RngCell
    
    'Capitalize words within parentheses
    
    End Sub

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,236

    Re: Capitalize words within parentheses

    Hi Perry,

    Try this:
    Sub mcrzzProperCaseTEST2()
    'Proper Case selected cells with Exceptions for Prepositions
    'Subordinate conjuctions will be capitalized -- because, as, who, if, that, what, why, that, when, where
    
    'Following will be in lower case:
    'a, an, the, and, but, for, nor, yet, by, with, on, to, of, at, around
    
    Dim txtString As String
    Dim RngCell As Range
    Dim StartChar As Double
    Dim EndChar As Double
    Dim Parined As String
    
    
    'Do not convert exceptions in cells selected to proper case
    For Each RngCell In Selection
    
        txtString = StrConv(RngCell.Text, vbProperCase)
        txtString = Application.Substitute(txtString, " Of ", " of ")
        RngCell.Value = txtString
        
        StartChar = InStr(RngCell.Text, "(")
        EndChar = InStr(RngCell.Text, ")")
        If StartChar > 0 And EndChar > 0 Then
            If StartChar < EndChar Then
                txtString = Mid(RngCell.Value, StartChar, EndChar - StartChar)
                txtString = WorksheetFunction.Substitute(RngCell.Text, txtString, StrConv(txtString, 1))
                RngCell.Value = txtString
            End If
        End If
    Next RngCell
    
    End Sub
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Update cell - Capitalize words on condition
    By Parth007 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-15-2016, 05:47 AM
  2. Executing methods - parentheses or no parentheses?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-23-2015, 07:57 PM
  3. [SOLVED] Extracting all text from parentheses (including parentheses)
    By j4ke101 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 05-10-2013, 08:03 AM
  4. Replies: 6
    Last Post: 01-18-2013, 12:01 PM
  5. Capitalize everything
    By Garren1013 in forum Excel General
    Replies: 6
    Last Post: 06-21-2011, 11:30 AM
  6. Replies: 6
    Last Post: 01-13-2011, 03:00 AM
  7. How to add parentheses...
    By hello_lpc in forum Excel General
    Replies: 4
    Last Post: 11-10-2008, 03:02 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1