Data validation in a list box

Padawan018

Board Regular
Joined
Sep 29, 2006
Messages
63
I have a user form with a list box and I want to make sure that the user selects an item within the list box. The code I have is:

if Listbox1.value = "" then
msgbox("Please select one of the entries.")
end if

any help would be appreciated.

Thanks.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
What's the actual question?

Try this.
Code:
If Listbox1.ListIndex = -1 then
  Msgbox("Please select one of the entries.")
End If
 
Upvote 0
Thanks Norie Unfortunately the error check not picking up.

I want to know how can I error check a listbox to make sure that a selection is made.
 
Upvote 0
I'm sorry but you haven't really asked a question or explained what the problem is.:)

Where did you try your (or my) code?
 
Upvote 0
I am writing the code in VBA for a user form. I have a command button and when the button is clicked it checks all the entry boxes(text, combo, and list). All of the error checks work except the one for the list box. Is there code to error check a list box to make sure a selection is made in the list box.
 
Upvote 0
The code I posted should work, and the code you posted might also work.

Without seeing the rest of your code it's hard to tell where your problem lies.

Is the code actually being triggered when you click the command button?
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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