600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > excel中用正则匹配_excel 利用正则表达式匹配工作表中的数据

excel中用正则匹配_excel 利用正则表达式匹配工作表中的数据

时间:2023-09-28 03:20:20

相关推荐

excel中用正则匹配_excel 利用正则表达式匹配工作表中的数据

excel 利用正则表达式匹配工作表中的数据

sheet1中A列放需要匹配的数据

sheet2中A列放正则表达式,可以是多个,但至少一个

匹配到了则在sheet1中C列对应行显示相关标记内容,比如本案例中显示1111

Sub Test()

atr = Worksheets("Sheet1").Range("a65536").End(xlUp).Row

btr = Worksheets("Sheet2").Range("a65536").End(xlUp).Row

a = Worksheets("Sheet1").Range("a1:a" & atr).Value

b = Worksheets("Sheet2").Range("a1:a" & btr).Value

ReDim c(1 To atr, 1 To 1)

Set reg = CreateObject("vbscript.regexp")

With reg

.Global = True

.IgnoreCase = True

For ar = 1 To atr

For br = 1 To btr

If btr = 1 Then

.Pattern = b

Else

.Pattern = b(br, 1)

End If

If .Test(a(ar, 1)) Then

c(ar, 1) = "1111"

Exit For

End If

Next

Next

End With

Range("c1:c" & atr) = c

Set reg = Nothing

End Sub

原文:/yorke/p/6170857.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。