我在Excel中有一些文本项目,并且id喜欢大写每个单词的第一个字母。但是,很多文本都包含短语'IT'并使用当前的大写方法(PROPER),它将其更改为'It'。有没有办法只将每个单词的第一个字母大写,而不是将每个单词中的其他字母大写?
答案 0 :(得分:2)
这是一种VBA方式,将其添加到模块& =PrefixCaps("A1")
Public Function PrefixCaps(value As String) As String
Dim Words() As String: Words = Split(value, " ")
Dim i As Long
For i = 0 To UBound(Words)
Mid$(Words(i), 1, 1) = UCase$(Mid$(Words(i), 1, 1))
Next
PrefixCaps = Join(Words, " ")
End Function
答案 1 :(得分:0)
答案 2 :(得分:0)
修复文本中的双空格:
Public Function PrefixCaps(value As String) As String
Dim Words() As String: Words = Split(value, " ")
Dim i As Long
For i = 0 To UBound(Words)
If Len(Words(i)) > 0 Then
Mid$(Words(i), 1, 1) = UCase$(Mid$(Words(i), 1, 1))
End If
Next
PrefixCaps = Join(Words, " ")
End Function`