SEARCH IN ARRAY

User avatar
sal21
PlatinumLounger
Posts: 4497
Joined: 26 Apr 2010, 17:36

SEARCH IN ARRAY

Post by sal21 »

DIM MYSTRING As String, MYARRAY() As String
...

MYSTRING = "1-NORD-OVEST|2-NORD-EST|4-SUD|3-CENTRO|5-ISOLE"
MYARRAY = Split(MYSTRING, "|")
...

Ho to check if

VALORE="3-CENTRO"

if VALORE exists in array or in MYSTRING?
Last edited by HansV on 06 Oct 2023, 12:07, edited 1 time in total.
Reason: SERCAH --> SEARCH

User avatar
HansV
Administrator
Posts: 79444
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SEARCH IN ARRAY

Post by HansV »

Code: Select all

    If Instr("|" & MYSTRING & "|", "|"&VALORE & "|") Then
        ' Found
    Else
        ' Not found
    End If
Best wishes,
Hans

User avatar
p45cal
2StarLounger
Posts: 166
Joined: 11 Jun 2012, 20:37

Re: SEARCH IN ARRAY

Post by p45cal »

in array:

Code: Select all

If IsError(Application.Match(VALORE, MYARRAY, 0)) Then
  'not found
Else
  'found
End If

User avatar
HansV
Administrator
Posts: 79444
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SEARCH IN ARRAY

Post by HansV »

Sal21 works in VB6, not in Excel...
Best wishes,
Hans

snb
5StarLounger
Posts: 614
Joined: 14 Nov 2012, 16:06

Re: SEARCH IN ARRAY

Post by snb »

Code: Select all

msgbox ubound(filter(myarray,"3-CENTRO"))>-1