zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    JVM类加载的过程
    接口文档设计
    代码规范及CodeReview要点
    Linux权限
    Linux文件
    UltraEdit编辑器基础技巧
    Android环境配置
    JDK 环境配置
    xml没有提示解决办法<eclipse>
    mysql事务实例
  • 原文地址:https://www.cnblogs.com/yorke/p/6170857.html
Copyright © 2011-2022 走看看