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.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
What's the actual question?

Try this.
Code:
If Listbox1.ListIndex = -1 then
  Msgbox("Please select one of the entries.")
End If
 

Padawan018

Board Regular
Joined
Sep 29, 2006
Messages
63
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
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?
 

Padawan018

Board Regular
Joined
Sep 29, 2006
Messages
63
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
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?
 

Forum statistics

Threads
1,141,756
Messages
5,708,332
Members
421,565
Latest member
Lastadiego

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
Top