Excel Macro to Convert to CamelHumpNotation

This is a macro that convert values to CamelHumpNotation

Sub FixCamelHump()
'
' FixCamelHump Macro
'
    Dim strValue As String

    Range("A1").Select
    strValue = ActiveCell.Value
    Do While strValue <> ""
        ActiveCell.Value = FixThisString(strValue)
        ActiveCell.Offset(1, 0).Select
        strValue = ActiveCell.Value
    Loop
End Sub

Private Function FixThisString(strValue As String)
    Dim intCnt As Integer
    Dim blnStartOfWord As Boolean
    Dim strBuild As String
    Dim strCurrentChar As String

    For intCnt = 1 To Len(strValue)
        strCurrentChar = Mid(strValue, intCnt, 1)
        If IsLetter(strCurrentChar) = True Then
            If blnStartOfWord = False Then
                blnStartOfWord = True
                strBuild = strBuild & UCase(strCurrentChar)
            Else
                strBuild = strBuild & LCase(strCurrentChar)
            End If
        Else
            If blnStartOfWord = True Then
                blnStartOfWord = False
            End If
            strBuild = strBuild & strCurrentChar
        End If
    Next
    FixThisString = strBuild
End Function

Private Function IsLetter(strChar As String) As Boolean
    If Asc(strChar) >= 97 And Asc(strChar) <= 122 Or Asc(strChar) >= 65 And Asc(strChar) <= 90 Then
        IsLetter = True
        Exit Function
    End If
    IsLetter = False
End Function

Leave a Reply

Your email address will not be published. Required fields are marked *