Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1961|回复: 4

[已解决]查找单括号中文字。.rar

[复制链接]
发表于 2016-11-4 10:12 | 显示全部楼层 |阅读模式
查找单括号中文字。.rar (8.14 KB, 下载次数: 5)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-11-4 10:45 | 显示全部楼层
Sub test()
    Dim i, x
    For i = 2 To 4
        x = Cells(i, "i")
        x = VBA.Replace(x, "〉", ">")
        Cells(i, "g") = tq(x)
    Next i
End Sub

Function tq(str)
    Dim matchs As Object, match As Object
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = ".(?=>)"
        Set matchs = .Execute(str)
        For Each match In matchs
            tq = tq & "," & match
        Next
    End With
    tq = Mid(tq, 2)
End Function

评分

参与人数 1 +3 收起 理由
水木 + 3 我和小伙伴都惊呆了!非常好,非常感谢!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2016-11-4 11:05 | 显示全部楼层
爱疯 发表于 2016-11-4 10:45
Sub test()
    Dim i, x
    For i = 2 To 4

老师:您好!非常好,先谢谢!没想到另有一种情况,我当时没有考虑到,请谅解。再求助:问题是在查找的内容中,有重复的,请去重复。 查找单括号中文字。.rar (8.75 KB, 下载次数: 8)
回复

使用道具 举报

发表于 2016-11-4 11:29 | 显示全部楼层    本楼为最佳答案   
Sub test()
    Dim i, x
    For i = 2 To 4
        x = Cells(i, "i")
        x = VBA.Replace(x, "〉", ">")
        Cells(i, "g") = tq(x)
    Next i
End Sub

Function tq(str)
    Dim matchs As Object, match As Object, d
    Set d = CreateObject("scripting.dictionary")
    d.RemoveAll
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = ".(?=>)"
        Set matchs = .Execute(str)
        For Each match In matchs
            d(match.Value) = ""
        Next
    End With
    tq = Join(d.keys, ",")
End Function

评分

参与人数 1 +3 收起 理由
水木 + 3 我和小伙伴都惊呆了!非常感谢!

查看全部评分

回复

使用道具 举报

发表于 2017-6-14 22:26 | 显示全部楼层
Sub 提取() '2017.6.14
Dim regex As New RegExp
  Set d = CreateObject("scripting.dictionary")
Dim rng As Range
Dim m As IMatch2
With regex
      .Global = True
      .Pattern = "(?:<|〈)(.+)(?:>|〉)"
      For Each rng In Range("i2:i4")
          If .test(rng) Then
             Set ma = .Execute(rng)
             For Each m In ma
                 x = m.SubMatches(0)
                 d(x) = ""
             Next m
          End If
          rng.Offset(0, -1) = Join(d.keys, "、")
          d.RemoveAll
      Next rng
End With
End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-25 09:12 , Processed in 0.398869 second(s), 16 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表