+ Reply to Thread
Results 1 to 5 of 5

VB Macro for Proper Case to Ignore "/" & "-"

Hybrid View

  1. #1
    Registered User
    Join Date
    10-07-2008
    Location
    virginia
    Posts
    26

    VB Macro for Proper Case to Ignore "/" & "-"

    I have a Excel text document that I compile from multiple sources, and if they don't leave a "white space" before a "/", "-", or "(" the Proper Case command does not capitalize the word that immediately follows that symbol.

     Sub Proper_Case_Inner(Optional mySelection As String)
         Application.ScreenUpdating = False
         Application.Calculation = xlCalculationManual
         Dim cell As Range
         Dim rng As Range
         On Error Resume Next   'In case no cells in selection
         If mySelection = "" Then Set rng = Selection _
             Else Set rng = Range(mySelection)
         For Each cell In Intersect(rng, _
                rng.SpecialCells(xlConstants, xlTextValues))
            cell.Formula = StrConv(cell.Formula, vbProperCase)
    ......

    Thanks for your help in advance.

    jlcford
    Last edited by jlcford; 10-08-2008 at 07:52 AM.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hi JLC,

    This probably isn't the greatest code, but it should do what you're asking, at least for the characters /, - and (
    Sub Proper_Case_Inner(Optional mySelection As String)
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        Dim cell As Range
        Dim rng As Range
        On Error Resume Next   'In case no cells in selection
        If mySelection = "" Then Set rng = Selection Else Set rng = Range(mySelection)
        For Each cell In Intersect(rng, rng.SpecialCells(xlConstants, xlTextValues))
            cell.Formula = Replace(cell.Formula, "/", "/ ")
            cell.Formula = Replace(cell.Formula, "-", "- ")
            cell.Formula = Replace(cell.Formula, "(", "( ")
            cell.Formula = StrConv(cell.Formula, vbProperCase)
            cell.Formula = Replace(cell.Formula, "/ ", "/")
            cell.Formula = Replace(cell.Formula, "- ", "-")
            cell.Formula = Replace(cell.Formula, "( ", "(")
    ......
    This will append a space after each of those symbols, then do your conversion to proper case, then remove those added spaces.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Instead of StrConv, use
    WorksheetFunction.Proper
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    I'll be right back.. have to go smack my forehead.

  5. #5
    Registered User
    Join Date
    10-07-2008
    Location
    virginia
    Posts
    26

    Thumbs up Code Worked

    Thanks for your input. The code you suggested worked perfectly.

    jlcford

+ 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. activate each cell
    By melaniethomson in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-07-2008, 05:59 AM
  2. counting letters but not working in new 2007 excel
    By melaniethomson in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-29-2008, 04:20 AM
  3. Auto change colour of cell when text / letter entered into cell
    By Nik_AU in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-26-2007, 07:36 AM
  4. pls turn this into VB macro
    By vickyho1008 in forum Excel General
    Replies: 11
    Last Post: 12-03-2006, 05:12 PM
  5. type mismatch
    By Mikeyhend in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2006, 01:17 PM

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