Results 1 to 10 of 10

Thread: VBA - uppercase of the first letter in each word, while the rest remains intact

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Administrator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,306
    Location
    Here is a revised function, you could convert it to a sub if you needed to:

    Function FixString(rCell As Range)    
        Dim var As Variant, too As Variant, Exclusion As Boolean
        
        Application.Volatile
        too = Split("with,a,of", ",")
        var = Split(rCell, " ")
        
        For x = LBound(var) To UBound(var)
            Exclusion = False
    
            For y = LBound(too) To UBound(too)
                If LCase(too(y)) = Application.Trim(LCase(var(x))) Then
                    var(x) = too(y)
                    Exclusion = True
                    Exit For
                End If
            Next y
            
            If Exclusion = False Then
                var(x) = UCase(Left(var(x), 1)) & Right(var(x), Len(var(x)) - 1)
            End If
            
            If Application.Trim(LCase(var(x))) = "dot" Then var(x) = " "
        Next x
        
        FixString = Application.Trim(Join(var))
        
    End Function
    Hope this helps
    Last edited by georgiboy; 05-22-2018 at 09:24 AM.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2408, Build 17928.20080

Posting Permissions

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