正则表达式 – 清除excel中的错误数据,用大写字母拆分单词
我在Mac OSX上使用excel 2011.我有一个包含大约3000个条目的数据集.在包含名称的字段中,许多名称未分开.名字和姓氏用空格分隔,但是单独的名字被捆在一起.
这就是我所拥有的,(一个单元格):
这是我想要完成的任务,(一个单元格,逗号后用逗号分隔的逗号):
我发现了一些VBA脚本会用大写字母分隔单词,但是我试过的那些会添加空格,我不需要像这样的空格… Function splitbycaps(inputstr As String) As String Dim i As Long Dim temp As String If inputstr = vbNullString Then splitbycaps = temp Exit Function Else temp = inputstr For i = 1 To Len(temp) If Mid(temp,i,1) = UCase(Mid(temp,1)) Then If i <> 1 Then temp = Left(temp,i - 1) + " " + Right(temp,Len(temp) - i + 1) i = i + 1 End If End If Next i splitbycaps = temp End If End Function 还有一个我在这里找到的使用RegEx,(原谅我,我只是学习所有这些,所以我听起来有点愚蠢)但是当我尝试那个时,它根本不起作用,我的研究我指出了一种方法来添加对库的引用,这将添加必要的工具,以便我可以使用它.不幸的是,在我的生活中,我不能找到如何在我的mac版本的excel上添加对库的引用…我可能做错了,但这是我无法工作的答案.. . Function SplitCaps(strIn As String) As String Dim objRegex As Object Set objRegex = CreateObject("vbscript.regexp") With objRegex .Global = True .Pattern = "([a-z])([A-Z])" SplitCaps = .Replace(strIn,"$1 $2") End With End Function 我通过excel通过VBA添加自定义功能基本上是全新的,甚至可能有更好的方法来实现这一点,但似乎我所得到的每个答案都不能很好地获得正确的数据.谢谢你的回答! 解决方法
我在
Split Uppercase words in Excel的功能需要udpdating来进行额外的字符串匹配.
您可以在单元格B1中使用此函数来获取A1中的文本,如下所示 你清洗所做的一个假设是人们只有两个名字,所以
被打破了
实际上应该发生什么? (如果是这样,需要进行小调整) 码 Function SplitCaps(strIn As String) As String Dim objRegex As Object Set objRegex = CreateObject("vbscript.regexp") With objRegex .Global = True .Pattern = "([a-z])([A-Z])" SplitCaps = Replace(.Replace(strIn,"$1,$2"),"<br>",",") End With End Function (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |