DEV Community

Cover image for #36 — Match The First Part of The Cell Value
Judith-Excel-Sharing
Judith-Excel-Sharing

Posted on

#36 — Match The First Part of The Cell Value

Problem description & analysis:
An Excel worksheet has multiple columns of source data that contains empty cells, as the following range C3:D19 shows. It also contains data items, which are separated into two parts by “-”, used for comparisons, as range F3:F7 shows.

original table
Task: Compare each column of the source data with the first part of the data item, and after each column of data, list all matching data items, as shown below:

desired table
Solution:
Use SPL XLL to do this:

=spl("=d=transpose@n(?1),transpose@n(d.(E@1(?2).select(d.~.pos(substr@l(~,$[-])))))",C3:D19,F3:F7)
Enter fullscreen mode Exit fullscreen mode

As shown in the picture below:

result table with code entered
Explanation:
transpose@n function transposes a sequence. E@1 convers a multilayer sequence to a single-layer one. substr@l searches for the specified character in a string and returns the substring before the specified character; here the option is lowercase letter l. pos() function finds whether a sequence contains a certain member or not; ~ represents the current member.

In the above, we use one formula to handle all columns. We can also use the following formula to first handle column C in cell C21 and then drag the formula to the other columns.

=spl("=E@1(?2).select(E@1(?1).pos(substr@l(~,$[-])))",C3:C19,$F$3:$F$7)
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
judith677 profile image
Judith-Excel-Sharing

Please feel free to try SPL XLL out and see the magic yourself ⬇️

📊SPL download address: scudata.com/download-Desktop

🚀Plugin Installation Method: c.scudata.com/article/1652061135502

📊References to other rich Excel operation cases: c.raqsoft.com/article/1651916536524

🚀SPL Programming (YouTube FREE courses): youtube.com/playlist?list=PLQeR-Ih...

Collapse
 
judith677 profile image
Judith-Excel-Sharing

For more Excel tasks and solutions, check out the detailed tutorial and code here:
🔸Discord: discord.gg/hgbKEvJ4
🔸Reddit: reddit.com/r/esProc_Desktop/