[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『テキストボックスの色で条件を変える』(SDP)
テキストボックスが35個あります。
全て色がグレーだった場合メッセージ"選択してません"と出したいのですが、何回も"選択してません"と出てしまいます。
何がおかしいのでしょうか?
Private Sub CommandButton36_Click()
For j = 1 To 35
If Me.Controls("CommandButton" & j) = &HFF0000 Then
UserForm1.TextBox5.Value = Me.Controls("CommandButton" & j).Caption
Unload UserForm2
j = j + 1
Else
MsgBox "選択してください"
End If
Next
End Sub
< 使用 Excel:Excel2010、使用 OS:Windows10 >
For j = 1 To 35
If False Then '省略 Else MsgBox "選択してください" End If Next
とりあえず、仕組みとしてはこうなっているのでそうなります。
(きまぐれおじさん) 2021/09/21(火) 22:37
(SDP) 2021/09/21(火) 22:52
これはCommandButtonなのかCommandButtonと名付けられたTextboxなのか
プロパティを指定していないので色を参照していない
&HFF0000はグレーとは無関係
(きまぐれおじさん) 2021/09/21(火) 22:59
MeはUserform1です。
j = j + 1は全くできないので付け足しました。意味はわかってなくForの使い方がいまいち理解してません。
(SDP) 2021/09/21(火) 23:22
Private Sub CommandButton36_Click() Dim j For j = 1 To 35 If Me.Controls("CommandButton" & j).Backcolor = &HFF0000 Then Me.TextBox5.Value = Me.Controls("CommandButton" & j).Caption Unload UserForm2 Exit Sub End If Next MsgBox "選択してください" End Sub
これでコマンドボタン1〜35からボタン背景色が&HFF0000のものを見つけてテキストボックス5にコマンドボタンの文字を転写します。
(対象テキストボックスが1つなので最初の1つ転写したときに処理を終えます)
(きまぐれおじさん) 2021/09/22(水) 00:49
Private Sub CommandButton36_Click() Dim j,str For j = 1 To 35 If Me.Controls("CommandButton" & j).Backcolor = &HFF0000 Then str = str & Me.Controls("CommandButton" & j).Caption End If Next If str <> "" Then Me.TextBox5.Value = str Unload UserForm2 Else MsgBox "選択してください" End If End Sub
別案。
コマンドボタンを全部回って条件に合うものをすべて繋げてテキストボックスに出力する。
(きまぐれおじさん) 2021/09/22(水) 00:58
(SDP) 2021/09/22(水) 11:27
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.