title: How do I apply a custom format such as "Text:" 0.0% in Excel VBA
body: <p>I would like Excel VBA to write either a number or a percentage, depending upon a user control.  </p>
  
  <p>In Excel, I can hit Ctrl 1 to apply a custom format such as "Text:" 0.0% or "Text:" 0.0.  </p>
  
  <p>I have managed to write the text and then use either Format() or Round(), depending upon the control value.  However, Format has two decimal places, and I would like a single decimal place.</p>
  
  <p>Here is some illustrative code.  As stated above, I would like to have control over the number of decimal places for the percentages (e.g. 0, 1, 2).</p>
  
  <pre><code>Select Case sControl
  Case "Percentage"
    oRange = "Text: " &amp; Format(dvalue + 0.000001, "Percent")
  Case "Numeric"
    oRange = "Text: " &amp; Round(dvalue + 0.000001, 1)
  End Select
  </code></pre>
  
  <p>Any pointers on how to do this would be great.  I am adding 0.000001 to dvalue in both cases, as I understand that this helps to maintain traditional rounding accuracy.</p>
  
  <p>Cheers
  Tim</p>