2013-02-27 58 views
1

这是一个优秀的问题。我需要在字符串中分隔文本和数字。该字符串可以以数字开头或可以以字符开头。文字或数字之间可能有空格。因此,公式需要足够多才能将其分隔为2列,其中一列仅包含文本,其他仅包含数字。请帮忙。擅长单独的文本和数字

非常感谢您

文本字符串的例子

  • 07 7878 8788 ABC JKSDKJK
  • ABCVG HDH 656688
  • AGSGD89789798798
  • 798 99AJSUDFK
+0

你可以使用替换的一些嵌套的版本()与“标准”,更换所有的号码,基本上消除它们,只留下字母。 – Kevin 2013-02-27 09:44:57

+0

我尝试使用公式等 = TRIM(LEFT(A1,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A1&“1,2,3,4, 5,6,7,8,9,0" )) - 1)) – 2013-02-27 23:24:48

回答

0

只要作为你所有的细胞在列A中的格式为{数字+空格} {非数字文本}或者相反,您可以通过查找每个单元格中第一个数字字符和第一个非数字非空格字符的位置开始。然后,您可以使用这些加上一些额外的逻辑来使用MID来提取适当的子字符串。

我贴数组公式在这里做到这一点: Excel formula to find the first non-alpha character in a cell?

您将需要作出轻微修改第二个公式,所以它返回第一个字符的位置是不是数字或空格:

=MIN(
     IF(
        1*ISNUMBER(
        1*MID(
         A1, 
         ROW(INDIRECT("A1:A"&LEN(A1))), 
         1 
       ) 
       ) + 
       1*(MID(
         A1, 
         ROW(INDIRECT("A1:A"&LEN(A1))), 
         1 
       )=" "), 
      LEN(A1)+1, 
      ROW(INDIRECT("A1:A"&LEN(A1))) 

     ) 
    ) 
1

纯文本

功能阿尔法(BYVAL strInString由于〜应变克)作为字符串 昏暗lngLen只要,斯特劳特作为字符串 昏暗我只要,strTmp作为字符串

lngLen = Len(strInString) 
strOut = "" 
For i = 1 To lngLen 
    strTmp = Left$(strInString, 1) 
    strInString = Right$(strInString, lngLen - i) 
    'The next statement will extract BOTH Lower and Upper case chars 
    If (Asc(strTmp) >= 65 And Asc(strTmp) <= 90 Or Asc(strTmp) >= 97 And Asc(strTmp) <= 122) Then 
     'to extract just lower case, use the limit 97 - 122 
     'to extract just upper case, use the limit 65 - 90 
     strOut = strOut & strTmp 
    End If 
Next i 
Alphas = strOut 

端功能

只有编号

功能Numerics的(BYVAL strInString作为字符串)作为字符串 昏暗lngLen长,斯特劳特作为字符串 昏暗我只要,strTmp作为字符串

lngLen = Len(strInString) 
strOut = "" 
For i = 1 To lngLen 
    strTmp = Left$(strInString, 1) 
    strInString = Right$(strInString, lngLen - i) 
    If (Asc(strTmp) >= 48 And Asc(strTmp) <= 57) Then 
     strOut = strOut & strTmp 
    End If 
Next i 
Numerics = strOut 

端功能

只有数&文本

功能字母数字(BYVAL strInString作为字符串)作为字符串 昏暗lngLen长,斯特劳特作为字符串 昏暗我只要,strTmp作为字符串

lngLen = Len(strInString) 
strOut = "" 
For i = 1 To lngLen 
    strTmp = Left$(strInString, 1) 
    strInString = Right$(strInString, lngLen - i) 
    'The next statement will extract BOTH Lower and Upper case chars 
    If (Asc(strTmp) >= 65 And Asc(strTmp) <= 90 Or Asc(strTmp) >= 97 And Asc(strTmp) <= 122 or Asc(strTmp) >= 48 And Asc(strTmp) <= 57) Then 
     'to extract just lower case, use the limit 97 - 122 
     'to extract just upper case, use the limit 65 - 90 
     strOut = strOut & strTmp 
    End If 
Next i 
Alphanumerics = strOut 

End Function

这可以在Excel中使用过,但是这是由我修改访问使用