List box click event no longer working

Courgettey

New Member
Joined
Jan 25, 2017
Messages
3
Hello - I am new to posting on here but have found these forums very helpful so hopefully you can help!

I am using a userform with a listbox. The listbox is pre populated. When the user selects an item from the listbox, I would like to search previous outputs (in column C) in the worksheet to see if there are any duplicates, alert the user and stop them from progressing.

My code did work... but then I closed and re-opened my file and it no longer works. Can anyone help or spot where I went wrong?

Code:
Code:
Private Sub ListBox_Click()
With Sheet4.Range("C2:C500")
    For ListItem = 0 To ListBox.ListCount - 1
    
        If Asset_List.Selected(ListItem) = True Then
                If Selection.Find(What:=ListBox.List(ListItem), LookIn:=xlValues) Is Nothing Then
'
                Else
                   MsgBox "This listbox item has already been submitted, please choose another  "
                    Exit Sub
                End If
        End If
        
    Next ListItem
End With

End Sub
 
Last edited by a moderator:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Welcome to the forum.

Did you change the name of the listbox?
 
Last edited:
Upvote 0
Hi Rory,

Oops, yes - the code should say:
Code:
Private Sub Asset_List_Click()
With Sheet4.Range("C2:C500")
    For ListItem = 0 To Asset_List.ListCount - 1
    
        If Asset_List.Selected(ListItem) = True Then
                If Selection.Find(What:=Asset_List.List(ListItem), LookIn:=xlValues) Is Nothing Then
                 '   MsgBox "NOT Found " & Asset_List.Selected(ListItem)
                 '   Exit Sub
                Else
                   MsgBox "This asset has already been submitted, please choose another  "
                    Exit Sub
                End If
        End If
        
    Next ListItem
End With


End Sub
 
Last edited by a moderator:
Upvote 0
Does it work like that?
 
Upvote 0
Are you sure that is the correct name for the control? What appears in the left hand dropdown in the VB code editor?
 
Upvote 0

Forum statistics

Threads
1,215,632
Messages
6,125,913
Members
449,274
Latest member
mrcsbenson

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