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

问题描述 投票:0回答:1

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

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。

谢谢。

excel text-extraction
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.