Shweta
Well-known Member
- Joined
- Jun 5, 2011
- Messages
- 514
Hi All,
I am using the below code for extracting numbers from an alphanumeric text. But this is not giving the correct output. Please suggest what changes are required to make it work.
Regards,
Shweta
I am using the below code for extracting numbers from an alphanumeric text. But this is not giving the correct output. Please suggest what changes are required to make it work.
Code:
Sub extract_numbers()
Dim i As Integer
Dim j As Integer
Dim arr As Variant
arr = Application.Transpose(Sheet1.Cells(1, 1).CurrentRegion.Resize(, 1).Value)
For i = LBound(arr) To UBound(arr)
For j = 1 To Len(arr(i))
If IsNumeric(VBA.Mid(arr(i), j, 1)) Then
arr(i) = arr(i) & VBA.Mid(arr(i), j, 1)
End If
Next
Next
Sheet1.Cells(1, 2).Resize(UBound(arr), 1).Value = Application.Transpose(arr)
End Sub
Shweta