这是一个很好的问题。我需要在字符串中分隔文本和数字。字符串可以以数字开头,也可以以字符开头。文本或数字之间可能有空格。因此,公式需要具有足够的通用性,以将其分成2列,其中一列仅包含文本,另一列仅包含数字。请帮忙。
非常感谢
文本字符串示例
答案 0 :(得分:1)
仅文字
函数Alphas(ByVal strInString As String)As String Dim lngLen As Long,strOut As String Dim i As Long,strTmp As String
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
结束功能
仅限数字
函数数字(ByVal strInString As String)As String Dim lngLen As Long,strOut As String Dim i As Long,strTmp As String
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
结束功能
仅限数字&amp;文本 强>
函数字母数字(ByVal strInString As String)As String Dim lngLen As Long,strOut As String Dim i As Long,strTmp As String
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
结束功能
这也可以在excel中使用,但我对其进行了修改以便进行访问
答案 1 :(得分: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)))
)
)