|
▼γ さん:
お返事ありがとうございます。
某サイトで質問したのですが回答が得られなくて。。。
私自身に問題があるみたいですね。反省します。
>質問1)
>質問2)
⇒htt p://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12144985737
上記に画像が貼ってあるので、イメージしていただけるとありがたいです。
>質問3)
> いったんすべてのチェックボックスをFalseにしてから、
> 家族構成を満たすcheckboxにTrueを設定するという普通の考え方では
> いけないのですか?
⇒その考えはしているのですが、自分でソースコードを組めなくて。。(涙)
以下に実際動いているコードを載せます。
'イメージ画にはありませんが、コマンドボタン1を押してから処理をスタート(クリア)するとします
Private Sub CommandButton1_Click()
Dim i As Integer
Dim cellvalue As String
i = 2
ComboBox1.Clear
Do
cellvalue = Cells(i, 1).Value
If cellvalue = "" Then
Exit Do
End If
If FindItem(ComboBox1, cellvalue) = False Then
ComboBox1.AddItem (cellvalue)
End If
i = i + 1
Loop
End Sub
Private Sub ComboBox1_Change()
Dim comboValue As String
comboValue = ComboBox1.Value
ComboBox2.Clear
Dim i As Integer
i = 2
Do
cellvalue = Cells(i, 2).Value
If cellvalue = "" Then
Exit Do
End If
If Cells(i, 1).Value = comboValue Then
If FindItem(ComboBox2, cellvalue) = False Then
ComboBox2.AddItem (cellvalue)
End If
End If
i = i + 1
Loop
End Sub
Private Sub ComboBox2_Change()
Dim i As Integer
Dim cellValue1 As String
Dim cellValue2 As String
Dim cellValue3 As String
i = 2
ComboBox3.Clear
Dim comboValue1 As String
Dim comboValue2 As String
comboValue1 = ComboBox1.Value
comboValue2 = ComboBox2.Value
Do
cellValue1 = Cells(i, 1).Value
cellValue2 = Cells(i, 2).Value
cellValue3 = Cells(i, 3).Value
If cellValue1 = "" Then
Exit Do
End If
If comboValue1 = cellValue1 And comboValue2 = cellValue2 Then
If FindItem(ComboBox3, cellValue3) = False Then
ComboBox3.AddItem (cellValue3)
End If
End If
i = i + 1
Loop
End Sub
Private Sub ComboBox3_Change()
Dim i As Integer
Dim cellValue1 As String
Dim cellValue2 As String
Dim cellValue3 As String
Dim cellValue4 As String
i = 2
ComboBox4.Clear
Dim comboValue1 As String
Dim comboValue2 As String
Dim comboValue3 As String
comboValue1 = ComboBox1.Value
comboValue2 = ComboBox2.Value
comboValue3 = ComboBox3.Value
Do
cellValue1 = Cells(i, 1).Value
cellValue2 = Cells(i, 2).Value
cellValue3 = Cells(i, 3).Value
cellValue4 = Cells(i, 4).Value
If cellValue1 = "" Then
Exit Do
End If
If comboValue2 = cellValue2 And comboValue3 = cellValue3 Then
If FindItem(ComboBox4, cellValue4) = False Then
ComboBox4.AddItem (cellValue4)
End If
End If
i = i + 1
Loop
End Sub
Private Sub ComboBox4_Change()
Dim i As Integer
Dim cellValue1 As String
Dim cellValue2 As String
Dim cellValue3 As String
Dim cellValue4 As String
Dim cellValue5 As String
i = 2
Dim comboValue1 As String
Dim comboValue2 As String
Dim comboValue3 As String
Dim comboValue4 As String
comboValue1 = ComboBox1.Value
comboValue2 = ComboBox2.Value
comboValue3 = ComboBox3.Value
comboValue4 = ComboBox4.Value
Do
cellValue1 = Cells(i, 1).Value
cellValue2 = Cells(i, 2).Value
cellValue3 = Cells(i, 3).Value
cellValue4 = Cells(i, 4).Value
If cellValue1 = "" Then
Exit Do
End If
If comboValue2 = cellValue2 And comboValue3 = cellValue3 Then
If FindItem(ComboBox4, cellValue4) = False Then
ComboBox4.AddItem (cellValue4)
End If
End If
i = i + 1
Loop
End Sub
Private Function FindItem(ByRef combo As ComboBox, ByVal item As String)
Dim i As Integer
For i = 0 To combo.ListCount - 1
If combo.List(i) = item Then
FindItem = True
Exit Function
End If
Next
FindItem = False
End Function
|
|