Ok so here is what I am trying to do. I have a form that has many comboboxes on it. I have made the default visibility on most of these false so that they are only seen when I want them to be. Now then, I have tried to trigger a change to the visibility with a Vlookup result. So I have cmb_mod1 which is my value that I want to use a arg1. The range will be worksheet("compressors").range(A1:b1000). Column that the expected result is located in is 2.
So if cmb_mod1.value = Jge_4 The lookup should search the compressors worksheet column a for the value of JGE_4. Then return a result of "4" for this particular choice from the dropdown. Finally the If condition. Now If ans = "4" then cmb_1cyl1.visible=true and cmb2cyl1.visible=true and cmb_3cyl1.visible=true and cmb_4cyl1.visible=true. However, I cannot get the visibility to change.
Hoping for any help is what may be causing my condition change. Code below:
Private Sub Cmb_mod1_Change()
'Make Cylinder Drop Down Boxes Visible equal to the number of throws of the compressor
Dim Ans As Integer
Dim arg1 As Variant
Dim myRng As Range
Dim arg4 As Boolean
arg1 = Cmb_mod1.Value
Set myRng = Worksheets("Compressors").Range("A1:B1000")
arg3 = 2
arg4 = False
Ans = Application.VLookup(arg1, myRng, arg3, arg4)
If Ans = "1" Then
cmb_1cyl1.Visible = True
ElseIf Ans = "2" Then
cmb_1cyl1.Visible = True And cmb_2cyl1.Visible = True
ElseIf Ans = "4" Then
cmb_1cyl1.Visible = True And cmb_2cyl1.Visible = True And cmb_3cyl1.Visible = True And cmb_4cyl1.Visible = True
ElseIf Ans = "6" Then
cmb_1cyl1.Visible = True And cmb_2cyl1.Visible = True And cmb_3cyl1.Visible = True And cmb_4cyl1.Visible = True And cmb_5cyl1.Visible = True And cmb_6cyl1.Visible = True
End If
End Sub
Bookmarks