+ Reply to Thread
Results 1 to 10 of 10

Control Font size with VBA

  1. #1
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Control Font size with VBA

    Is it possible to control font size by vba,in the example workbook you will see what I mean. I tried
    Shrink to Fit with no luck,just want max size font and keep data in box. Have about 30 of these cell that
    deep font size control. If only one word then font is size11, lot of words as low as 8. So fonts could be 8,9,10,or 11.

    Thanks for ideas.
    Attached Files Attached Files

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

    Re: Control Font size with VBA

    The shrink font will only start when the text overflows the width of the cell. It does not take cell height into account.

    One way would be to use a helper textbox shape with Resize shape to fit text set. You could then adjust the fontsize until the textbox size matches or is smaller than cell. Then apply that font size to cell.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Control Font size with VBA

    Found this code but can't make it go to size 8 ??
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Control Font size with VBA

    Think I got it by changing font style.

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

    Re: Control Font size with VBA

    try this 3 formula in H10:H12

    =REPT("Test",10)
    =REPT("Test",20)
    =REPT("Test",30)

  6. #6
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Control Font size with VBA

    Morning Andy
    Not sure what you mean,where do I put =REPT("Test",10)

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

    Re: Control Font size with VBA

    In cells H10:H12, then change selection to fire the event code. you should see all 3 fontsizes then

  8. #8
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Control Font size with VBA

    Sometime I feel so dumb,not sure what you mean.
    Do I put =REPT("Test",10) in H10
    Do I Put =REPT("Test",20) in H11
    Do I Put =REPT("Test",30) in H12

    Or do I add to VBA code?
    Sorry for not understanding

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

    Re: Control Font size with VBA

    You add the formula to the sheet. Basically the code you posted will alter the cells H10:H20 based on the length of the text in the cell.
    If the text is not long enough then font size 8 will not be applied. Those formula provided strings long enough to set font to 10, 9 and 8.

    Attached is an example using the textbox to help decide the font. Enter test text string in F2.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    03-05-2009
    Location
    usa
    MS-Off Ver
    Excel 2016 32Bit
    Posts
    1,173

    Re: Control Font size with VBA

    Thanks Andy, that explains it a lot better. Need to find a way to adapt to my workbook. In the example I used one cell but in workbook
    I have about 20 cell formatted the size in example. Will have to find a way to insert the text into right cell.

+ 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] BUG: Font Size / Control Size Changes
    By Mike Piston in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-19-2005, 12:05 PM
  2. [SOLVED] font size changes w/ control focus
    By mark kubicki in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  3. font size changes w/ control focus
    By mark kubicki in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  4. font size changes w/ control focus
    By mark kubicki in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  5. [SOLVED] font size changes w/ control focus
    By mark kubicki in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-17-2005, 01:05 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