Dlookup - how to match value in a table?

behedwin

Active Member
Joined
Dec 10, 2014
Messages
399
Hi

I want to make an if statement that looks for a matching value in a table´s column.

Table name: table1
column: name

I have a value being held in a variable called "username" (dont know if im explaining this correctly)
If i do a code
Code:
msgbox username
i do get the expected value i want... now i want to look if that value is stored in a table in a column.

Code:
If table1,column=name = username then
msgbox "value found in table"
else
msgbox "value not found in table"
end if

from what i have read i should do a DLookup line.... but i dont know how to write that.
Anyone able to help me?
 

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.
You want to use it in excel table? You could like this:

Code:
tName = "table1"
cName = "name"
uName = "steve"

If IsError(Application.Match(uName, Sheets("Sheet1").ListObjects(tName).ListColumns(cName).Range, 0)) Then
    MsgBox "Value doesnt exist"
Else
    MsgBox "Value does exist"
End If
 
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