开发者

Expression to test for one or more spaces in VBA to find matches in Excel cells

I am trying to use regular expressions in a macro for an Excel document.

Here is what I have so far:

dim regex
regex.pattern = "\s+"
for p = 3 to totalparamcount
    if (regex.test(Worksheets("table").Cells(p,1)) then
        msgbox ("blah blah")
    end if
next

The pattern I am tryin开发者_StackOverflow中文版g to match is one or more spaces, tabs, newlines, which I saw is denoted by "\s".

The line 'if (regex.test(Worksheets("table").Cells(p,1)) then' is getting this error:

Run-time error '424':

Object required

I am using VBA 7.0 in Excel.


You need to create the regexp object, ie

Dim regex
Set regex = CreateObject("vbscript.regexp")
regex.Pattern = "\s+"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜