Excel正则表达式? [英] Excel Regular Expressions?

查看:75
本文介绍了Excel正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有[111.222.33.4]格式的IP地址的文本文件。 但是,我想将其更改为111.222.033.004格式。 过去我在Word中成功使用了MS正则表达式, 我试图在Excel中使用相同的内容,而且
不起作用。 更改IP地址格式的最佳方法是什么? 

I have a text file with ip addresses in [111.222.33.4] format.  However, I want to change this into 111.222.033.004 format.  In the past I have used MS regular expressions in Word successfuly,  I have tried to use the same in Excel and they do not work.  What is the best way to change this format for the IP address? 

PS - 在工作中我们有Excel 2007附带的默认VBE,我们无法安装任何其他工具或者是库。

PS - At work we have the default VBE that comes with Excel 2007 and we cann ot install any other tools or libraries.

提前谢谢。

推荐答案

你好,布朗查普,

Hi brownchap,

 

我想到的一件事是用点分割成这个字符串然后用零来表示每个值。然后,将值作为字符串返回。

One thing that came up to my mind is to use a split into this string by dots and then fulfill each value with zeroes. Then, get the value back as string.

 

这将是这样的..

 

Function myFormat(ByVal sMyValue As String) As String
  
  Dim sResult As String
  Dim vValues As Variant
  Dim vItem As Variant
  
  vValues = Split(sMyValue, ".")
  
  For Each vItem In vValues
    
    sResult = sResult & Right("000" & vItem, 3) & "."
    
  Next vItem
  
  myFormat = Left(sResult, Len(sResult) - 1)

End Function

 

希望它有所帮助!


这篇关于Excel正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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