Excelです。
ComboBoxでRowSource内にない言葉を書き込んだ場合、エラーが出るんです。
RowSource内にない言葉を書き込んだ時に「もう一度選択し直すか」もしくは、その言葉をRowSourceに加えるにはどうすればいいですか?
現在: xyz = ComboBox1
Range("ABC").Find(xyz, LookAt:=xlWhole).Activate
NMmatgeさん こんにちは
昔に作ったもので参考になればうれしいです。
ユーザーフォームにボタンとコンボボックスを作って
下のプログラムを貼り付ければ動くと思います。
Private Sub CommandButton1_Click()
Dim count As Integer
Dim gyou As Integer
Dim i As Integer
For i = 0 To 9
count = count - (Cells(1 + 256 * i) = ComboBox1.Value)
gyou = gyou - (Cells(1 + 256 * i) <> "")
Next i
If count = 0 Then Cells(1 + 256 * gyou) = ComboBox1.Value
UserForm_Activate
End Sub
Private Sub UserForm_Activate()
Dim gyou As Integer
Dim i As Integer
For i = 0 To 9
gyou = gyou - (Cells(1 + 256 * i) <> "")
Next i
If gyou = 0 Then gyou = 1
ComboBox1.RowSource = "A1:A" & gyou
End Sub
サンプルで作成したので不都合な部分もあります
ご自分で改良してください。
もしよろしければ
今後の役に立つと思うので簡単に説明していただきたいのですが…
説明?このソースのどこに説明を入れろと?
順次デバックすればわかりますよ。
取り合えず
count = count - (Cells(1 + 256 * i) = ComboBox1.Value)
と言うのは
If Cells(1 + i, 1) = ComboBox1.Value Then
count = count + 1
endif
と同じです。
ちなみにComboBoxのRowSourceは
ComboBox1.RowSource = "ABC"でセットさていると解釈しましたが、
考え方は↓の様になります。
Range("A1:A" & gyou)
ありがとうございました。
ツイート | ![]() |