+ Reply to Thread
Results 1 to 6 of 6

Code to shrink font size after the first 3 characters and spaces

Hybrid View

trickyricky Code to shrink font size... 03-14-2011, 10:54 PM
protonLeah Re: Code to shrink font size... 03-15-2011, 12:13 AM
trickyricky Re: Code to shrink font size... 03-15-2011, 12:36 AM
trickyricky Re: Code to shrink font size... 03-15-2011, 09:32 AM
Andy Pope Re: Code to shrink font size... 03-15-2011, 09:40 AM
trickyricky Re: Code to shrink font size... 03-15-2011, 09:57 AM
  1. #1
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Code to shrink font size after the first 3 characters and spaces

    I'm looking for a way to quickly make the font size of a text string within a cell smaller than the first 3 characters. For Example:

    11 Smaller
    12 Smaller
    13 Smaller
    14 Smaller
    etc...

    The numbers I want the font size to be 11 for example and for the "Smaller" part I want the font size to be 9.

    I need to be able to do this for multiple cells quickly instead of manually going to each cell and highlighting the smaller part and changing the font size.

    Thanks in advance!
    Last edited by trickyricky; 03-26-2011 at 12:45 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Code to shrink font size after the first 3 characters and spaces

    Does this one work?

    Sub test()
        Dim SpaceLocation  As Long, _
            TextLength  As Long
        
        With ActiveCell
            TextLength = Len(.Text)
            SpaceLocation = InStr(1, .Text, " ")
            .Characters(Start:=1, Length:=SpaceLocation - 1).Font.Size = 11
            .Characters(Start:=SpaceLocation + 1, Length:=TextLength - SpaceLocation - 1).Font.Size = 9
        End With
    End Sub
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Re: Code to shrink font size after the first 3 characters and spaces

    Close. It's setting the first three characters to font size 11 which is right, but it's not setting the last letter on the very end to size 9 like it should. Also would be slick if it could work on a range of cells instead of just the active cell.

    P.S.

    Some of the cells i'm wanting to do this for actually look more like this:

    11 NO GRP
    12 NO FP
    13 ENDORUSH
    14 SPD GRP
    15 SPD FP
    etc..

    In other words some text in the cells after the numbers have spaces in them and should all be size 9.
    Last edited by trickyricky; 03-15-2011 at 12:41 AM.

  4. #4
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Re: Code to shrink font size after the first 3 characters and spaces

    Okay here's what I do, I go ahead and set the font for everything to size 9 then I Run this code:

    Sub Font_Sizer()
        Dim SpaceLocation  As Long, _
            TextLength  As Long
        
        With ActiveCell
            TextLength = Len(.Text)
            SpaceLocation = InStr(1, .Text, " ")
            .Characters(Start:=1, Length:=SpaceLocation - 1).Font.Size = 11
        End With
    End Sub
    But I want this to work on a selection of cells. I tried changing the active cell part to selection but it didn't work like I hoped. Please help if you can!

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Code to shrink font size after the first 3 characters and spaces

    Sub X()
    
        Dim rngCell As Range
        Dim lngPos As Long
        
        If Not TypeOf Selection Is Range Then Exit Sub
        
        For Each rngCell In Selection.Cells
            lngPos = InStr(rngCell.Value, " ")
            If lngPos > 0 Then
                rngCell.Font.Size = 11
                rngCell.Characters(lngPos + 1, Len(rngCell.Value)).Font.Size = 9
            End If
        Next
        
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Re: Code to shrink font size after the first 3 characters and spaces

    Booyah! Thank you kindly! You will get the scales!

+ 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