如何创buildmacros来获取多个值?
我是初学者在Excel VBA我有巨大的名单,其中一列中的名字和姓氏没有任何空格或符号和一些名称是在大写字母,有些没有大写字母,他们是同一列什么是可能的macros让他们之间的空间…或任何可能的方式….
提前致谢….
不可靠,但会让你简单的名字。 select名称的范围并运行macros。
Sub InsertSpacesInNames() Dim pos As Long: pos = 0 Dim uc As Long: uc = 0 For Each cell In Selection For i = 1 To Len(cell.Value) If Asc((Mid(cell.Value, i, 1))) >= 65 And Asc((Mid(cell.Value, i, 1))) <= 90 Then uc = uc + 1 pos = i End If Next i If uc = 2 Then cell.Value = Mid(cell.Value, 1, pos - 1) & " " & Mid(cell.Value, pos, Len(cell.Value)) End If uc = 0 pos = 0 Next End Sub
我的输出:
此macros只有在以下情况下才能正常工作 :
- 你用它简单的名字(没有像Jean-Pierre LeCosteau那样的复合名字,这个名字是Jean-Pierre LeCosteau )
- 全名只有两个大写字母。
假设你知道名字,然后使用公式的简单例子:
AB 1 AmandaWinslet = "Amanda" & " " & RIGHT(A1, LEN(A1) - LEN("Amanda"))) // result is Amanda Winslet
VBA的做法是:
Sub AddSpace() Range("A1") = "Amanda" & " " & VBA.Right$(Range("A1"), Len(Range("A1")) - Len("Amanda")) End Sub
您将需要循环VBA中的列表,并使FirstName
variables。 你的文章假设你有某个地方的名字