vba to select a font size that makes variable text clearly visible in a fixed size cell

cjcass

Well-known Member
Joined
Oct 27, 2011
Messages
683
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I have a range of cells that are fixed in size (the row height / column width cannot change). The text string that goes into each cell is variable and could have anywhere from 10 to 150 characters in it. The cells are currently set for wrapped text with a font size 14 which satisfies most of the text that goes into the cells. However when the text string increases in character count it is not always completely visible in every cell. Is there any code that will choose the optimum font size to display the wrapped text clearly and fill the cell as much as possible (at 100% page zoom)? I have used the code below for other jobs but it's clunky, requires lots of thresholds, and is not accurate as characters vary in size.
Any help much appreciated.
Rgds,

Code:
For Each c In Range("MP318:MP417")
    Select Case Len(c)
        Case 0 To 40
            c.Font.Size = 14
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi,
Thanks for your help, that's a pretty good idea but am not sure that will work because text wrapping is driven by word length - so lots of small words could result in more characters on one line then you would get with a couple of long words (I think?).
Rgds,
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,712
Members
452,995
Latest member
isldboy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top