I am trying to check if an element from one string is contained in another without looping. As the loop results in a significant increase in run time.
The routine below does that but I am concerned that it may also cause a problem as it may find a result it should not.
To explain this is the log of the following script
Vals1= (PBCT, STBA, PNFP, BK, AOS, SXT, BMTC, LNT, PNM, WBS, SON, EIG, EWBC)
Vals2 = (AOS, BK, BUSE, CAC, EGBN, GGG, GSBC, LNT, NBHC, PNM, RY, STBA, PNFP, WBS, PBCT, SXT, BMTC, SON, EIG, EWBC)
The first line contains the element I am looking for in the second line. An example of my problem. If I was looking for “BCTS” , my script finds it in the second line “PBCT,SXT”.
tell application "Microsoft Excel" --
set Check to name of last sheet of active workbook --
select worksheet Check --Have to Switch so the "String value " command works
tell active sheet to set UsedRows to ((first row index of (get end (last cell of column 1) direction toward the top)))
set Rng1 to "A3:A" & UsedRows
set Vals1 to string value of range Rng1
log Vals1
select worksheet "TestOptionData" --
tell worksheet "TestOptionData" to set UsedRows to ((first row index of (get end (last cell of column 1) direction toward the top)))
set Rng2 to "A3:A" & UsedRows
set Vals2 to string value of range Rng2
log Vals2
select worksheet Check
end tell
repeat with NewStock from 1 to count of Vals1
set StockSYMnew to (item NewStock of Vals1)
if (Vals2 as string) contains StockSYMnew then
display dialog Vals2 as string
else
display dialog "Does not"
end if
end repeat