VBA Excel - Extraindo Dígitos - Extract Digits (Remove Alphabets) from Selected Range

Inline image 1
Código para extrair dígitos:

Function ExtractDigits (ByVal cell As String) As Object
        'This function will extract 1st continuous set of digits.
        Dim i As Long, flag As Long 

        flag = 0
        ExtractDigits = "" 

        For i = 1 To Len(cell)
            If Mid(cell, i, 1) >= "0" And _
               Mid(cell, i, 1) <= "9" Then
                flag = 1
                ExtractDigits = ExtractDigits & Mid(cell, i, 1)
                ExtractDigits = ExtractDigits * 1
                If flag = 1 Then Exit Function
            End If
        Next i
End Function

    Sub Extract_Digits()
        ' This module will extract digits from selected range of cells using above User-defined function.         Dim MyCell As Range
        Dim tmpCol As Integer
        Dim flag As Boolean

        tmpCol = Selection.Column

        For Each MyCell In Selection.Cells
                MyCell.Value = ExtractDigits(MyCell.Value)

        MyCell = Nothing
    End Sub

Tags: VBA, Excel, Number, Text, User Defined Function (UDF), VBA Macro

Related Posts Plugin for WordPress, Blogger...


diHITT - Notícias