Sunday, July 4, 2010

UDF to extract letters from a cell


If you want to extract letters from a cell. Try this UDF



Function extract_letters(Str As String)
    Dim i  As Long
    Dim text1 As String
    text1 = ""
        For i = 1 To Len(Str)
            If (Asc(Mid(Str, i, 1)) > 64 And Asc(Mid(Str, i, 1)) < 90) Or (Asc(Mid(Str, i, 1)) > 96 And Asc(Mid(Str, i, 1)) < 123) Then
                text1 = text1 & Mid(Str, i, 1)
            End If
        Next i
    extract_letters = text1
End Function







Steps to Use

  • Copy the below code
  • Press Alt+F11 to open VBA editor
  • Paste it in any public module or module 1
  • For example you want to extract letters  from cell A1 in Cell B1 . In B1 = extract_letters(A1)

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...