Scripts

Excel Macro to Convert to CamelHumpNotation

Written in 2011 for the Windows versions of the time. Check that the tool or steps still suit your environment before using them.

Prerequisites

  • Microsoft Excel (VBA macro)
  • Values in column A starting at A1

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 Then
        IsLetter = True
        Exit Function
    End If
    If Asc(strChar) >= 65 And Asc(strChar) <= 90 Then
        IsLetter = True
        Exit Function
    End If
    IsLetter = False
End Function

Posted on

No comments yet

Comments are moderated and appear once approved.