Excel Macro to Convert to CamelHumpNotation

This is a macro that convert values to CamelHumpNotation

Sub FixCamelHump()
' FixCamelHump Macro
    Dim strValue As String

    strValue = ActiveCell.Value
    Do While strValue <> ""
        ActiveCell.Value = FixThisString(strValue)
        ActiveCell.Offset(1, 0).Select
        strValue = ActiveCell.Value
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)
                strBuild = strBuild & LCase(strCurrentChar)
            End If
            If blnStartOfWord = True Then
                blnStartOfWord = False
            End If
            strBuild = strBuild & strCurrentChar
        End If
    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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.