3
是否有快速的方法(或任何方式)將正確的案例文本轉換爲單個單詞。我有幾千行的行,並認爲要求SO比手動分割文本更好。 Google無法幫助Excel ProperCase to words
例如, 「」 EffectiveFromDate應該翻譯爲 「有效起始日期」
是否有快速的方法(或任何方式)將正確的案例文本轉換爲單個單詞。我有幾千行的行,並認爲要求SO比手動分割文本更好。 Google無法幫助Excel ProperCase to words
例如, 「」 EffectiveFromDate應該翻譯爲 「有效起始日期」
試試這個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
圓滑,它的工作原理應該是/謝謝。非常感激 – Krishna