title: Given a fixed cel width, can I change the fontsize so that the text will fit inside the cell?
body: <p>I have code that will automatically adjust the height of a cell, so that text will fit inside that cell.<br>
  However now I want to change the fontsize of the text inside the cell, so that the font will shrink and grow to make the text fit inside the cell, so I don't have to make the cell width a fixed size.</p>
  
  <p>How do I do this in VBA?  </p>
  
  <p>I need to know the width of text, given a font size</p>
  
  <p>Option 1.</p>
  
  <pre><code>TextWidth = WidthOfAText(Range("A1").Value)
  FontAdjustmentFactor = Range("A1").EntireColumn.ColumnWidth / TextWidth
  FontSize = Range("A1").Font.Size * FontAdjustmentFactor
  Range("A1").Font.Size = Max(4, Min(10, FontSize))
  </code></pre>
  
  <p>or I need to know whether the text will fix and do some sort of trial and error routine.</p>
  
  <p>Option 2.</p>
  
  <pre><code>Range("A1").Font.Size = 10
  While (Text_does_not_fit AND Range("A1").Font.Size &gt;= 5) 
    Range("A1").Font.Size = Range("A1").Font.Size - 1
  Wend
  </code></pre>
  
  <p>How do I do this? (Preferably using code like in option 1)</p>