Write continuous numbers in a string of numbers as intervals
In an Excel worksheet, a cell contains a string made up of an ordered integer sequence. There are missing numbers, and the sequence is not continuous:
1,2,3,4,5,6,7,8,9,13,14,15,16,17,18,25,26,27,28,29,30,31,32
We want to find all continuous sub-sequences, write them in the form of intervals using the hyphen, and separate intervals with the comma.
1-9,13-18,25-32
Use SPL XLL to do this:
=spl("=?.split@pc().group@i(~!=~[-1]+1).(if(~.len()==1,~1,~1 / $[-] / ~.m(-1))).concat@c()",A1)
split@pc splits a string into a sequence, during which the function automatically parses the data type and uses comma as the separator. group@i creates a new group whenever the specified condition is met; ~[-1] represents the directly previous members of the current one, and m(-1) is the last member of a sequence.
Source:https://www.reddit.com/r/excel/comments/1cpsncw/any_way_to_remove_integers_from_a_coma_sorted_list/
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_Desktop/
SPL Learning Material 👉 https://c.scudata.com
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProcDesktop
Linkedin Group 👉 https://www.linkedin.com/groups/14419406/