0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

チェックボックスを読み込み動作分岐させてみた

Posted at

はじめに

チェックボックスへのクリック動作をキーとして動くマクロの紹介は多々あるが、チェックボックスの状態を基に動作させるようなマクロの紹介が少なかった。
ググりつつ実装したものを振り返りを兼ねて簡易版に編集したうえで紹介していく

動作概要

マクロを実行した時点でのチェックボックスの状態(TRUEorFALSE)をによって動作を変える。

チェックが入っているとき(☑) →「チェック有」とメッセージボックスを出す
チェックが入っていないとき(☐) →「チェック無」とメッセージボックスを出す

コード

Sub チェックボックス動作分岐()
    
    If Sheets("Sheet1").CheckBox1.Value = True Then
        MsgBox ("チェック有")
    Else
        MsgBox ("チェック無")
    End If
    
End Sub

イメージ

【チェック有 時】
image.png

【チェック無 時】
image.png

TIPS

チェックボックスの挿入方法

開発タブ<挿入<activeXコントロール<チェック ボックス

複数のチェックボックスについて

「CheckBox(i)」
チェックボックスは増やした分(i)がカウントされ属性(?)として1チェックボックスに1つ付属されるため、チェックボックスごとに識別が可能。
1つ目 →「CheckBox1」
2つ目 →「CheckBox2」

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?