私は範囲を通り抜けて最初の条件をテストし、その値をコンボボックスに追加するForループを作成しました。その条件が見つからない場合は、各ループに対して2番目の条件を実行し、その条件に一致するすべての値を追加します。VBA forそれぞれForネストされた
私は以下のコードを書かれているし、それはIF
Dim Keys As Range, cell As Range
Set Keys = ThisWorkbook.Worksheets("keyHistory").Range("A2:A20000")
For Each cell In Keys
If cell.Value = WindowsUserName And cell.Offset(0, 4) = 1 Then Me.ComboBox1.AddItem cell.Value
Else
For Each cell In Keys
If cell.Offset(0, 4).Value = 1 And cell.Offset(0, 3) = "" Or cell.Value = "Spare" And cell.Offset(0, 4) = 1 Then Me.ComboBox1.AddItem cell.Value
Next cell
Next cell
Set Keys = Nothing
してください([IF-THEN-else文]についての読みhttps://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/if-then-else-ステートメント)。 –