[英]Excel Macro Unable to Separate String Address
Software: MS Excel 2016 软体: MS Excel 2016
Please note there can be any number of digits before West, ie 请注意,西之前可以有任意数字,即
123124234234West18th Street
2West 14th Avenue
12324West
Please assist with general solution 请协助一般解决方案
There is address, 31West 52nd Street
I am trying to split the 31
and West
so output will be 地址为
31
West
31West 52nd Street
我想将31
和West
分开,所以输出将是
31 West 52nd Street
Tried this Macro statement but it won't work, please guide 尝试了此宏语句,但无法正常工作,请指导
Selection.Replace What:="?@West ", Replacement:=" West " _ , LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat _ :=False, ReplaceFormat:=False
This is a sample of code, that would check for the first few chars. 这是代码示例,将检查前几个字符。 If they are digits, if would split them with a space from the rest:
如果它们是数字,则将它们与其他空格分开:
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
Thus, from input: 因此,从输入:
"31West 52nd Street"
"123Vityata Shampion"
We get output: 我们得到输出:
31 West 52nd Street
123 Vityata Shampion
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.