[VBA] How to Turn Off Option Buttons by Default in a UserForm

目次

Introduction

In this post, I will share how to set Option Buttons (also known as Radio Buttons) on a UserForm to be unselected (OFF) by default.

Environment:

  • OS: Windows 10 Pro
  • Version: 20H2

Background

I placed two option buttons, “Yes” and “No,” on a UserForm. However, when I opened the form, one of the buttons was already selected (ON). I wanted both buttons to be unselected (OFF) when the form first appears, so I looked for a way to configure this.

Solution: Set the “Value” Property to “False”

To turn off the initial selection of an Option Button, you simply need to set its Value property to False.

Steps

  1. Open VBE (Visual Basic Editor) Press Alt + F11 to open the VBA editor.
  2. Select the UserForm Open the target UserForm.
  3. Select the OptionButton Click on the Option Button you want to modify.
  4. Find “Value” in the Properties Window It is easier to find if you look at the “Alphabetic” tab in the Properties Window.
  5. Change the Value Change the Value property to False.

Note

Often, one button is set to True (selected) and the other to False (unselected) by default. If you want to ensure that both buttons are OFF when the form loads, you can also set this explicitly using the Initialize event in your code.

Private Sub UserForm_Initialize()
    OptionButton1.Value = False
    OptionButton2.Value = False
End Sub

This code forces all specified option buttons to be unselected when the form opens.

Summary

  • The initial state of an Option Button is controlled by the Value property.
  • Be aware that the default setting may be True, causing an unintended pre-selection.
  • Setting the property to False ensures the button starts as unselected.
  • For more flexible control, using the UserForm_Initialize event is also effective.

This small adjustment helps in designing user-friendly forms by ensuring no assumptions are made about the user’s choice.

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

私が勉強したこと、実践したこと、してることを書いているブログです。
主に資産運用について書いていたのですが、
最近はプログラミングに興味があるので、今はそればっかりです。

目次