Saltar al contenido

ejemplo de código de tutorial de excel vba select case

Investigamos en diferentes espacios para de esta manera regalarte la respuesta para tu inquietud, si continúas con preguntas puedes dejar tu pregunta y te respondemos sin falta.

Ejemplo 1: declaración de caso de excel vba

v ="z"SelectCase v
    Case1'code runs here if v = 1Case2'code runs here if v = 2Case3To5'code runs here if v = 3 or 4 or 5CaseIs<10'code runs here if v = 6 or 7 or 8 or 9Case10,15,20'code runs here if v = 10 or 15 or 20Case#12/25/2020#'code runs here if v = #12/25/2020#Case"abc"'code runs here if v = "abc"CaseIs<="m"'code runs here if v <= "m"CaseTrue'code runs here if v = TrueCaseElse'Code runs here if v did not match any of the above cases.'In this example, since v = "z", the 'Case Else' would match'and only the code here would execute.EndSelect'Notes: The Select Case construct must be terminated by 'End Select'.'       Only one case (at most) will have its code run.'       Each case is evaluated in order, from the top down, until match found. '       No more cases are evaluated once a case matches the Select Expression.'       An execution speed optimization is to place more likely cases on top.'       The special 'Case Else' is optional.'       If no case matches the Select Expression, execution exits the construct.'A very useful variation is to set the Select Expression to True (or False):SelectCaseTrueCase a <= b And b <= c: Debug.Print "b is between a and c"Case a = b:             Debug.Print "a = b"Case e > f:             Debug.Print "e > f"Case InStr(x,"z"):     Debug.Print "'z' is in x"Case IsEmpty(m):        Debug.Print "m is Empty"EndSelect'In this second example, only the firt True case will print.'''

Ejemplo 2: excel vba imitando el operador in de otros idiomas

'VBA does not have an IN operator, but we can do this:Function IsIn(a, b)AsBoolean
    IsIn = InStrB(","& b &",",","& a &",")EndFunction'--------------------------------------------------------------------

MsgBox IsIn(2,"1,2,3")'<-- displays True
MsgBox IsIn("d","a,b,c")'<-- displays False

Te invitamos a añadir valor a nuestro contenido participando con tu experiencia en las ilustraciones.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)


Tags : /

Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *