Vba Condense Multiple OR

Eisasuarez

Well-known Member
Joined
Mar 23, 2012
Messages
653
Hi All

How can i have a vba code to consense multiple or criterias

Say i wanted to check to see

If txtboxtest.value <> "Name1" or txtboxtest.value <> "Name2" etc... (There could be multiple Names to check for)
How can i condense this rather than writing multiple or statements?

P.s i could also have a range set up on say sheets Access Range A2 to last row therefore i coukd say if the txtboxtest.value <> (In that range list) then do what ever but im stuck how to condense this?

Would i need a loop?
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Eisasuarez

Well-known Member
Joined
Mar 23, 2012
Messages
653
So how would i do this to say if the the value is in the access list then you have access else you dont

E.g I have a named range called access on the access sheet

Code:
SELECT CASE textboxName.value
      CASE IS (IN THE ACCESS RANGE LIST
             MSGBOX "YOU HAVE ACCESS"
CASE ELSE
MSGBOX "YOU DONT HAVE ACCESS"
END SELECT
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,500
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Code:
If Not Iserror(application.match(textboxName.value, sheets("access").range("access"), 0)) then
msgbox "You have access"
Else
Msgbox "You don't have access"
End If

for example.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,787
Messages
5,524,870
Members
409,607
Latest member
charleswaynemc

This Week's Hot Topics

Top