Home > Mobile >  Get only numeric values in VBA
Get only numeric values in VBA

Time:10-08

I have a string

Dim A As String
A = "A23"
B = "bd4"

I need to get only the numeric values as the output as below

A = 23
B = 4

CodePudding user response:

You could use a regex replacement here:

Dim A As String: A = "A23"
Dim AOut As String
Dim pattern As String: pattern = "\D "
Set regEx = CreateObject("VBScript.RegExp")

With regEx
    .Global = True
    .Pattern = pattern
End With

AOut = regEx.Replace(A, "")
Debug.Print AOut
  •  Tags:  
  • vba
  • Related