how to create macro using replace function? [close

2019-09-21 06:49发布

I am beginner in VBA excel and trying to create a userdefine funcation.

i want to replace multiple value and want defined value in return using vba so what would be the correct macro that have replace function..... i have data like this.... 011 25655527 and return value should be like this "01125655527" 92-9818425034 and return value should be like this "9818425034" and there is number of space and hyphen and other thing i can't do it manually as it take lot of time i hope you understand.... thanks in advance....

please help me for fixing

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-21 07:14

This function returns a string containing all numeric characters in the cell it is given as a parameter. I think that is what you want?

Function remove_non_numbers(r As Range) As String
  Dim oRegEx As Object

  Set oRegEx = CreateObject("vbscript.regexp")
  oRegEx.Pattern = "[^\d]+"
  oRegEx.Global = True

  remove_numbers = oRegEx.Replace(r, vbNullString)
End Function
查看更多
登录 后发表回答