I am using the following code which works perfectly:
If ComboBox3.ListIndex = 0 And ComboBox4.ListIndex = 3 Then
ID1 = "GS-T10-"
Elseif ComboBox3.ListIndex = 0 And ComboBox4.ListIndex = 4 Then
ID1 = "PB-"
Elseif ComboBox3.ListIndex = 0 And ComboBox4.ListIndex = 5 Then
ID1 = "PE-"
As you can see It is if statement with AND operator evaluating 2 conditions. However notice that my first condition is always the same (ComboBox3.ListIndex = 0), and only the second condition is changing. Is there a way to just write the first condition (which is not changing) once at the beginning of the IF Statement and hence only write the second condition after each Elseif??
Thank you,
You should "take out" the repeating condition to outer If
statement, like this:
If ComboBox3.ListIndex = 0 Then
If ComboBox4.ListIndex = 3 Then
ID1 = "GS-T10-"
Elseif ComboBox4.ListIndex = 4 Then
ID1 = "PB-"
Elseif ComboBox4.ListIndex = 5 Then
ID1 = "PE-"
End If
End If
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments