Friday, November 8, 2013

How to Extract Numbers from Alphanumeric Strings from a Range or Cell Value

Excel VBA Macro to Extract Only Numbers From Text String from a Range or Cell Value
Sub ExtractNumbers()
Dim i As Integer
Dim j As Integer

On Error Resume Next

For i = 2 To 10                       'Rows Having Alpha Numeric Strings
If Cells(i, 1) = "" Then Exit For

For j = 1 To Len(Cells(i, 1))
If WorksheetFunction.IsNumber(Mid(Cells(i, 1), j, 1) + 0) = False 
Then GoTo Jnext:
Cells(i, 2) = Cells(i, 2) & Mid(Cells(i, 1), j, 1)
Jnext:
Next j

Next i
End Sub

Output :


String
Extracted Numbers
A1E5I9O15U
15915

Thanks, Tamatam

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog