如何从Excel中的文本字符串中提取特定数字?

如何从Excel中的文本字符串中提取特定数字?,excel,text,excel-formula,numbers,office365,Excel,Text,Excel Formula,Numbers,Office365,我有一个像这样的数据集 abcdefg-1004958-2019-services xyz-3104568-technology ltd-UG32594 xxfgdrtg-GH267384-FO(1082564)-2016软件 FO501117898-ahdndje-2016-service 我需要从这个数据集中提取100495831045681082564501117898。换句话说,任何大于100000的数据都必须返回 有什么公式可以做到这一点吗?因为我有10000多个这样的条目,它们的顺序

我有一个像这样的数据集

abcdefg-1004958-2019-services

xyz-3104568-technology ltd-UG32594

xxfgdrtg-GH267384-FO(1082564)-2016软件

FO501117898-ahdndje-2016-service

我需要从这个数据集中提取100495831045681082564501117898。换句话说,任何大于100000的数据都必须返回

有什么公式可以做到这一点吗?因为我有10000多个这样的条目,它们的顺序不均匀,而且我也不能用文本来表示列


任何帮助都将不胜感激。谢谢大家!

使用Microsoft365,您可以尝试:

B1
中的公式:

=MAX(FILTERXML("<t><s>"&CONCAT(IFERROR(MID(A1,SEQUENCE(LEN(A1)),1)*1,"</s><s>"))&"</s></t>","//s[.*0=0]"))
=MAX(FILTERXML(“&CONCAT(IFERROR(MID(A1,SEQUENCE(LEN(A1)),1)*1,”)和“//s[*0=0]”)

您可以使用用户定义的函数。以下是我得出的结论:

Function FunNumber(RngTarget As Range, Optional BlnReportAsNumber As Boolean = True, Optional BytPlacement As Byte = 1)
    
    'Declarations.
    Dim StrValue As String
    Dim BytPosition As Byte
    Dim StrString01 As String
    
    'Setting.
    StrValue = RngTarget.Cells(1, 1).Value
    
    'Covering each character in StrValue.
    For BytPosition = 1 To Len(StrValue)
        'Removing any non-numerica character from StrValue.
        If Not IsNumeric(Mid(StrValue, BytPosition, 1)) Then
            StrValue = Left(StrValue, BytPosition - 1) & " " & Right(StrValue, Len(StrValue) - BytPosition)
        End If
    Next
    
    'Removing leading and trailing spaces from StrValue.
    StrValue = Trim(StrValue)
    
    'Covering each character in StrValue but the last one.
    For BytPosition = 1 To Len(StrValue) - 1
        'Removing any multiple space.
        If Mid(StrValue, BytPosition, 2) = "  " Then
            StrValue = Left(StrValue, BytPosition - 1) & " " & Right(StrValue, Len(StrValue) - BytPosition - 1)
            BytPosition = BytPosition - 1
        End If
    Next
    
    'Setting FunNumber.
    FunNumber = ""
    
CP_Small_Number_Removed:

    'Covering each section of StrValue marked by a space.
    For BytPosition = 0 To UBound(Split(StrValue, " "))
        
        'Setting StrString01 as section of StrValue marked by space.
        StrString01 = Split(StrValue, " ")(BytPosition)
        
        'Checking for a number smaller than 100000.
        If Len(StrString01) < 6 Then
            
            'Removing the number smaller than 100000.
            Select Case BytPosition
                Case Is = 0
                    StrValue = Right(StrValue, Len(StrValue) - Len(StrString01) - 1)
                    GoTo CP_Small_Number_Removed
                Case Is < UBound(Split(StrValue, " "))
                    StrValue = Replace(StrValue, " " & StrString01 & " ", " ")
                    GoTo CP_Small_Number_Removed
                Case Is = UBound(Split(StrValue, " "))
                    StrValue = Left(StrValue, Len(StrValue) - Len(StrString01) - 1)
                    GoTo CP_Small_Number_Removed
            End Select
            
        End If
    Next
    
    
    'Setting FunNumber.
    FunNumber = Split(StrValue, " ")(BytPlacement - 1)
    
    'Resetting FunNumber as number if needed.
    If BlnReportAsNumber = True Then
        FunNumber = FunNumber * 1
    End If
    
End Function
函数FunNumber(RngTarget作为范围,可选blnreportanumber作为布尔值=True,可选BytPlacement作为字节=1)
"声明,。
作为字符串的Dim StrValue
Dim BytPosition作为字节
作为字符串的Dim StrString01
“背景。
StrValue=RngTarget.Cells(1,1).Value
'覆盖StrValue中的每个字符。
对于BytPosition=1到Len(标准值)
'从标准值中删除任何非数字字符。
如果不是数字(中间值(StrValue,BytPosition,1)),则
StrValue=Left(StrValue,BytPosition-1)和“”&右侧(StrValue,Len(StrValue)-BytPosition)
如果结束
下一个
'从StrValue中删除前导空格和尾随空格。
标准值=微调(标准值)
'覆盖StrValue中的每个字符,但最后一个字符除外。
对于BytPosition=1到Len(标准值)-1
'删除任何多个空间。
如果Mid(StrValue,BytPosition,2)=“”,则
StrValue=Left(StrValue,BytPosition-1)和“”&右侧(StrValue,Len(StrValue)-BytPosition-1)
BytPosition=BytPosition-1
如果结束
下一个
"设置一个数字。
FunNumber=“”
CP_小_数量_移除:
'覆盖由空格标记的标准值的每个部分。
对于BytPosition=0到UBound(拆分(StrValue,“”)
'将StrString01设置为用空格标记的StrValue的节。
StrString01=Split(StrValue,“”)(按位置)
“正在检查小于100000的数字。
如果Len(StrString01)<6,则
'删除小于100000的数字。
按位置选择大小写
大小写为=0
StrValue=Right(StrValue,Len(StrValue)-Len(StrString01)-1)
转到CP\u小号码\u已删除
案例

将其放置在模块中。假设字符串位于单元格A1中。在另一个单元格中写入
=FunNumber(A1)
,您将获得所需的结果。如果您想将其报告为文本(可能前导零很重要),您可以编写
=FunNumber(A1,FALSE)
。如果有多个大于100000的数字,并且您希望查找第二个,请编写类似于
=FunNumber(A1,2)
(当然,您可以指定您想要的是字符串还是数字,同时还可以指定您想要的是第二个或第三个或任何数字)。如果未找到大于100000的数字,则函数返回#VALUE error。

对于那些可以使用LibreOffice Calc的人,答案要简单得多,因为Calc默认支持正则表达式:

=REGEX(A1;"\d{6,}")

这个问题是关于Excel的,但由于答案的复杂性差异如此巨大,我不想保留LibreOffice的答案。

我认为正则表达式是解决这个问题的更好方法。正则表达式可能非常强大,但它有一个缺点,即它可能会变得(处理器)耗时。在您的例子中,正则表达式非常简单:
\d{6,}
,这意味着“查找一行上6位或更多位的字符串中的任何部分”。介绍了如何在excel中使用正则表达式,但还有许多其他工具可以为您完成此正则表达式任务。非常感谢,这就像是一个非常酷的把戏JvDV。挖掘帖子@Chris,谢谢。似乎有什么东西/有人从SO那里复制了它。=)@JvdV-ha。在过去的一段时间里,我把所有这些用例都放到了一个工作簿中。太有用了!!注意到了一些小的修改。我认为“//s[count(node())=0]”应该是“//s[count(node())=1]”,“//s[contains(concat(,preference:*[2]),“FA')]”没有根据示例字符串生成任何结果,“//s[not(node())]”向我抛出了一个值错误。不确定这是他们的复制粘贴错误,还是您的原始帖子中的错误。尽管如此,我还是想提一下:)@Chris,看起来很疯狂:
//s[count(node())=0]
是正确的语法。让我们想象一下
“ABC | 123 | DEF | 456 | XY-1A | ZY-2F | XY-3F | XY-4f | xyz | 123”
,您将看到它将为两个空节点返回两个错误值
//s[not(node())]
是另一个的等价项。两者都意味着返回空节点。不幸的是,Excel不会将这些值处理为空字符串值,而是返回(多个)错误。另外,
//s[contains(concat(,preference:*[2]),'FA')]
是正确的语法,在尝试时,它会将
“DEF”
返回给我。不