title: How to solve runtime error 11 division by 0 in vba?
body: <p>I have the following code..... </p>
  
  <pre><code>private sub textbox1_change()
  if textbox1.value = "" then exit sub 
  if textbox2.value = "" then exit sub 
  textbox3.value = cdbl(textbox1.value) / cdbl(textbox2.value)
  end sub 
  private sub textbox2_change()
  if textbox1.value = "" then exit sub
  if textbox2.value = "" then exit sub
  textbox3.value = cdbl(textbox1.value) / cdbl(textbox2.value)
  end sub 
  </code></pre>
  
  <p>Whenever textbox2 has a zero value there will be a message box prompting runtime error 11; division by zero. I tried to resolve it by using IIF condition as suggested by the user <strong>Scott Craner</strong> <a href="https://stackoverflow.com/questions/38231638/how-to-solve-runtime-error-6-in-vba">here</a></p>
  
  <pre><code>textbox3.value = cdbl(textbox1.value)/IIF(cdbl(textbox2.value) = 0 , 1 , cdbl(textbox2.value) ) 
  </code></pre>
  
  <p>I want to know if I can somehow assign the value of textbox3 as "NULL" or "NA" or "-" if the denominator is zero. I could not find anything credible on the internet. </p>
  
  <p>Thanks a lot !!</p>