DONUT PROJECT - VBA - Excel - Removendo os Caracteres Alfabéticos e Especiais

DONUT PROJECT - VBA - Excel - Removendo os Caracteres Alfabéticos e Especiais



'Remove All Alpha and Special characters from cell
Function Remove_AlphaSpecialChar (DataCell As Range) As String
     
    ' Declaração de Variável.
    Dim iCnt As Integer
    Dim IpData As Range
    Dim sData As String, sTmp As String
              
    If DataCell.Count <> 1 Then
        MsgBox ("Por favor, selecione uma célula"), vbInformation
        Exit Function
    End If
     
    ' Loop que checa todos os caracteres disponíveis na célula.
    For iCnt = 1 To Len(DataCell.Text)
        If Mid(DataCell.Text, iCnt, 1) Like "[0-9]" Then
            Let sData = sData & Mid(DataCell.Text, iCnt, 1)
        End If
    Next iCnt
     
    Let Remove_AlphaSpecialChar = sData
End Function