从Excel中的字符串中提取年份

时间:2017-12-25 13:49:36

标签: excel text-extraction

我有一个没有重复模式的覆盖日期列表。例如,我有以下字符串:

Available from 1951 until 1984;

Available from 1964 volume: 2 issue: 1 until 2002 volume: 20 issue: 4;

Available from 1958 volume: 1 issue: 1;

Available from 1970 issue: 24 until 1989 issue: 110;  Available from 1990 volume: 1 issue: 1 until 2001 volume: 12 issue: 4;

我试图仅将年份值提取到Excel中的不同列中,例如:

Available from 1951 until 1984; -> 1951 | 1984
Available from 1964 volume: 2 issue: 1 until 2002 volume: 20 issue: 4; -> 1964 | 2002
Available from 1970 issue: 24 until 1989 issue: 110;  Available from 1990 volume: 1 issue: 1 until 2001 volume: 12 issue: 4; -> 1970 | 1989 | 1990 | 2001

(如果可能,每年应出现在不同的栏目中) 有没有办法让我抽出岁月?我想写一个VB代码,但老实说我不熟悉VB。

谢谢。

1 个答案:

答案 0 :(得分:4)

使用此数组公式:

=IFERROR(INDEX(MODE.MULT(IF((TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",999)),(ROW($1:$50)-1)*999+1,999))="from")+(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",999)),(ROW($1:$50)-1)*999+1,999))="until"),SUBSTITUTE(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",999)),(ROW($1:$50))*999+1,999)),";","")*{1,1})),COLUMN(A:A)),"")

作为一个数组公式,需要在退出编辑模式时使用Ctrl-Shift-Enter而不是Enter来确认。

输入B1,按Ctrl-Shift-Enter。然后上下复制/拖动。

此公式会查找fromuntil并提取下一个"字"作为回报。如果该规则不一致,那么这将不起作用。

enter image description here