软件: MS Excel 2016
请注意West之前可以有任意数字,即
123124234234West18th Street
2West 14th Avenue
12324West
请协助一般解决方案
有地址,31West 52nd Street
我正在尝试拆分31
和West
,因此输出将
31 West 52nd Street
尝试了这条宏观声明,但它没有成功,请指导
Selection.Replace What:="?@West ", Replacement:=" West " _
, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat _
:=False, ReplaceFormat:=False
答案 0 :(得分:1)
这是一个代码示例,它会检查前几个字符。如果它们是数字,if将它们与其余部分分开:
Option Explicit
Public Sub TestMe()
Debug.Print fnStrStripMyNumber("31West 52nd Street")
Debug.Print fnStrStripMyNumber("123Vityata Shampion")
End Sub
Public Function fnStrStripMyNumber(strStr As String) As String
Dim lngCountDigits As Long
Dim lngCounter As Long
strStr = Trim(strStr)
For lngCounter = 1 To Len(strStr)
If IsNumeric(Mid(strStr, lngCounter, 1)) Then
lngCountDigits = lngCountDigits + 1
Else
Exit For
End If
Next lngCounter
strStr = Left(strStr, lngCountDigits) & " " & Right(strStr, Len(strStr) - lngCountDigits)
fnStrStripMyNumber = Trim(strStr)
End Function
因此,来自输入:
"31West 52nd Street"
"123Vityata Shampion"
我们得到输出:
31 West 52nd Street
123 Vityata Shampion
答案 1 :(得分:1)