+ Reply to Thread
Results 1 to 4 of 4

Custom formula to change to small caps

Hybrid View

  1. #1
    Registered User
    Join Date
    09-08-2006
    Posts
    5

    Custom formula to change to small caps

    I've seen macros for this but I need a formula that pulls from a different worksheet.
    Can someone help please?

    Here's what I've got so far:

    
    Function SmallCaps(myString As String)
    
    Dim CellLength%, i%, DefaultSize
    Dim OutString As String
    
    OutString = myString
    
    CellLength = Len(myString)
    DefaultSize = 12
    
    For i = 1 To CellLength
     With OutString.Characters(i, 1)
       If .Text = UCase(.Text) Then
          .Font.Size = DefaultSize
       Else
          .Text = UCase(.Text)
          .Font.Size = DefaultSize - 2
       End If
     End With
    Next i
    
    SmallCaps = CellLength
    
    End Function

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Custom formula to change to small caps

    A string doesn't have a font size. You need to do it after the data is copied.
    Sub SmallCaps()
        Const dSize As Double = 12
        Dim cell    As Range
        Dim i       As Long
    
        For Each cell In Selection
            For i = 1 To Len(cell.Text)
                With cell.Characters(i, 1)
                    If .Text = UCase(.Text) Then
                        .Font.Size = dSize
                    Else
                        .Text = UCase(.Text)
                        .Font.Size = dSize - 2
                    End If
                End With
            Next i
        Next cell
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    09-08-2006
    Posts
    5

    Re: Custom formula to change to small caps

    Okay. Thanks!

    I want to make a formula though.

    So I can type text into one cell and the formula will pull the text and format small caps into another cell.

    Any ideas for making this a formula, rather than a macro?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Custom formula to change to small caps

    It can't be done with a formula for the reason I explained in the first post -- string variables don't have fonts, they are just strings of characters. A cell can contain rich text, so you can format individual characters with varying font, font size, bold, italic ...
    Last edited by shg; 05-22-2009 at 11:20 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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