Excel ProperCase来说话

有没有一个快速的方法(或任何方式)将正确的案例文本转换为单个单词。 我有几千行的行,并认为要求SO比手动分割文本更好。 谷歌无法帮助

例如“”EffectiveFromDate应翻译为“生效date”

试试这个UDF:

Function ProperCaseToWords(x As String) As String Dim i As Byte 'A=65, Z=90 For i = 65 To 90 x = Replace(x, Chr(i), " " & Chr(i)) Next i ProperCaseToWords = Trim(x) End Function 

然后在任何单元格中调用它: =ProperCaseToWords(A1)

在这里输入图像说明

或者从Sub调用它:

 Dim cell As Range For Each cell In Range("A1:A100") cell.Value = ProperCaseToWords(cell.Value) Next 

试试这个代码:

 Sub SplitProper() Dim rgLoop As Range, lCharLoop As Long, lChar As Long, sTemp As String 'turn off updates to speed up code execution With Application .ScreenUpdating = False .EnableEvents = False .Calculation = xlCalculationManual .DisplayAlerts = False End With For Each rgLoop In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants, 2).Cells sTemp = rgLoop.Value For lCharLoop = Len(rgLoop.Value) To 2 Step -1 lChar = Asc(Mid(sTemp, lCharLoop, 1)) If lChar >= 65 And lChar <= 90 Then sTemp = Left(sTemp, lCharLoop - 1) & " " & Mid(sTemp, lCharLoop) End If Next rgLoop.Value = sTemp Next rgLoop 'turn off updates to speed up code execution With Application .ScreenUpdating = False .EnableEvents = False .Calculation = xlCalculationManual .DisplayAlerts = False End With End Sub