Compile error help

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Code:
Private Sub cmbSDPFLine_Enter()    Dim i As Long
    
    cmbSDPFLine.Clear
    cmbPrdCde.Enabled = False
    cmbPrdCde.Clear
    txtbxPrdctNm.Text = ""
    
    WS_Count = ActiveWorkbook.Worksheets.Count
    
    For i = 4 To WS_Count
        cmbSDPFLine.AddItem Sheets(i).Name
    Next
End Sub
As of now I have four sheets with the names of the different machines at our packaging facility. The above code populates a combo box called cmbSDPFLine with those sheet tab names of the machines.
On my userform I have two combo boxes. The first one is the one above mentioned. The other combo box is called cmbPrdCode which the Enabled is set to False until cmbSDPFLine contains a value. This part of the code is located in cmbSDPFLine Change.
Code:
if cmbsdpfline.Value=cmbSDPFLine.AddItem Sheets(i).Name then
The error that I am getting above is a "Compile error: Expected: Then or GoTo" and for whatever reason I am also getting another error "Compile error: Syntax error".
Code:
if cmbsdpfline.Value=cmbSDPFLine.AddItem Sheets(i).Name then    
cmbPrdCde.Enabled = True
End If
The above code is what I want to happen. Not sure if it will work.
What I want to achieve is if the cmbsdpfline value is equal to any of the machine sheet names that starts on sheet four, then enable cmbPrdCde combo box. Thank You for any help offered.
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
How about
Code:
If Len(cmbsdpfline.Value) > 0 Then cmbPrdCde.Enabled = True
 
Upvote 0
What I want to achieve is if the cmbsdpfline value is equal to any of the machine sheet names that starts on sheet four, then enable cmbPrdCde combo box. Thank You for any help offered.

Try this...

Code:
Private Sub cmbSDPFLine_Change()
    cmbPrdCde.Enabled = cmbsdpfline.ListIndex > -1
End Sub
 
Last edited:
Upvote 0
Thank you for the quick response. So basically if the length of the value inside cmbSDPFLine is greater than 0 or is not empty then cmbPrdCde is enabled. If that is correct, than thats so simple. Thank You very much.

After I tested that code. It worked. Thank You.
 
Last edited:
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top