title: How can I dynamically add a radio button on a form using VBA
body: <p>I want to dynamically add a radio button on a form, using VBA. </p>
  
  <p>I tried writing this code, but it crashes with 'Type Mismatch'</p>
  
  <pre><code>Dim optionBtn As OptionButton
  Set optionBtn = UserForm1.Controls.Add("Forms.OptionButton.1", "name", True)
  
  optionBtn.Left = 10
  optionBtn.Top = 10
  optionBtn.Width = 30
  optionBtn.Group = "q1"
  </code></pre>
  
  <p>I also tried doing this:</p>
  
  <pre><code>Dim optionBtn As Control
  Set optionBtn = UserForm1.Controls.Add("Forms.OptionButton.1", "name", True)
  
  optionBtn.Left = 10
  optionBtn.Top = 10
  optionBtn.Width = 30
  optionBtn.Group = "q1"
  </code></pre>
  
  <p>but I get a Control, not a OptionButton - how can I cast it to a OptionButton ? (sorry, I'm new to VB)</p>