如何使用替换功能创建宏? [英] how to create macro using replace function?

查看:139
本文介绍了如何使用替换功能创建宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA excel的初学者,并试图创建一个用户定义函数。



我想替换多个值,并希望使用vba返回定义的值,所以会是什么正确的宏有替换功能.....我有这样的数据....
011 25655527和返回值应该像这样01125655527
92-9818425034和返回值应该是这个9818425034
,有数量的空格和连字符和其他事情我不能手动做,因为它需要很多时间,我希望你明白....
提前感谢...



请帮我修复

解决方案

此函数返回字符串包含单元格中作为参数给出的所有数字字符。我想这是你想要的?

 函数remove_non_numbers(r As Range)As String 
Dim oRegEx As Object

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

remove_numbers = oRegEx.Replace(r,vbNullString)
结束函数


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

解决方案

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

这篇关于如何使用替换功能创建宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆