Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referring to dropdown list value in VBA 2

Status
Not open for further replies.

rafal36

Programmer
Oct 16, 2008
5
Hi everyone,
I have a dropdown list (data range) named "nr_tyg3" and I want to check if value in a given cell belongs to that list or not.
How do I refer to that dropdown list?

IF variable1 <> value_from_dropdown THEN do_something

Thanks for your tips.
 

If this is on a UserForm and your dropdown list is named nr_tyg3, try something like:
Code:
Dim i As Integer
Dim blnIsFound As Boolean

For i = 0 to nr_tyg3.ListCount - 1
    If MyVariable = nr_tyg3.List(i) Then
        [green]'found it[/green]
        blnIsFound = True
        Exit For
    End If
Next i

If blnIsFound Then
    MsgBox "BINGO!"
Else
    MsgBox "Sorry  :-("
End If

Have fun.

---- Andy
 
My dropdown list is not in userForm, it's in a separate sheet. So now excel says "Object required" :(
 



Hi,

I have a dropdown list (data range) named "nr_tyg3"

You have a DATA RANGE named "nr_tyg3", that you are refernecing in a dropdown.

I want to check if value in a given cell belongs to that list or not.

How do you refer to the named range?
Code:
dim r as range, bFound as Boolean
bFound = false
for each r in [nr_tyg3]
  if variable1 = r.value then bFound=true
next
if not bFound then do something
or
Code:
if iserror(application.match(variable1,[nr_tyg3],0)) then do something


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top