Proper Case with extra rules in Excel

前端 未结 4 972
闹比i
闹比i 2021-01-25 00:19

I have used vba for Proper Case in Excel but I need to add an exception rule for it to save much manual editing. I need the first letter after \"-\" to also be Capitalized, exam

4条回答
  •  醉话见心
    2021-01-25 01:01

    Here is a little VBA Function using Split wich should do the desired work:

    Function properCase(str As String) As String
    
    Dim splitStr() As String
    
    splitStr = Split(str, "-")
    
    Dim i As Integer
    
    For i = LBound(splitStr) To UBound(splitStr) Step 1
    
        splitStr(i) = UCase(Left(splitStr(i), 1)) & Right(splitStr(i), Len(splitStr(i)) - 1)
    Next i
    
    properCase = Join(splitStr, "-")
    End Function
    

提交回复
热议问题