title: Dynamically setting of cells' NumberFormat in VBA excel when the uncertainty calculation in consideration
body: <p>I need to dynamically set the NumberFormat, via VBA, to imported text file values, as just below:</p>
  <p>Imported values number type is &quot;General&quot;, so I want to change to &quot;Number&quot;, but preserve the decimal point</p>
  <pre class="lang-none prettyprint-override"><code>12.324 ............................ 3 decimal points  
  2.12 .............................. 2 decimal points  
  0.00123 ............................5 decimal points  
  12.1234567 ........................ 7 decimal points
  </code></pre>
  <p>And all the data in the same column.</p>
  <p>Code is simple:</p>
  <pre><code>Range(&quot;A1&quot;).Numberformat =&quot;##0.0##&quot;
  Range(&quot;A2&quot;).Numberformat =&quot;#0.0#&quot;
  Range(&quot;A3&quot;).Numberformat =&quot;#0.0####&quot;
  Range(&quot;A4&quot;).Numberformat =&quot;##0.0######&quot;
  </code></pre>
  <p>So, I need to dynamically set &quot;#&quot;.</p>
  <p>The reason for setting the number after decimal point is very important for calculating the uncertainty result. In calculations, there is a need for the resolution which means how many digits after the decimal point appears on the measurement device that doing calibrations.</p>
  <hr />
  <p>I found a solution.</p>
  <pre><code>  res_dec_point = Len(Split(res_val &amp; &quot;,&quot;, &quot;,&quot;)(1))
    kes_dec_point = Len(Split(kes_val &amp; &quot;,&quot;, &quot;,&quot;)(1))
  
    MyNumberFormat_res = &quot;0.&quot;
    For i_num = 1 To res_dec_point
      MyNumberFormat_res = MyNumberFormat_res &amp; &quot;0&quot;
    Next i_num
    
    MyNumberFormat_kes = &quot;0.&quot;
    For i_num = 1 To kes_dec_point
      MyNumberFormat_kes = MyNumberFormat_kes &amp; &quot;0&quot;
    Next i_num
  </code></pre>
  <p>Thank you <a href="https://stackoverflow.com/users/10968406/bdra">https://stackoverflow.com/users/10968406/bdra</a></p>