Excel精英培训网

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

[分享] 【烟花原创】VBA零基础之第74篇 单元格对象Range(十八)

[复制链接]
发表于 2014-1-9 00:33 | 显示全部楼层 |阅读模式
 不知道上一篇的示例把大家绕晕没,绕晕了的就再晕一次,没晕的也再试试定力。
 示例:
 数据截图:
   73-2.jpg

  Dim rg As Range
  With Range("a1").CurrentRegion
   'SearchOrder参数演示,是先行还是先列
   Set rg = .Find(what:="张三",LookIn:=xlValues, _
    lookat:=xlPart, MatchCase:=False, _
    MatchByte:=False, searchorder:=xlByColumns)
   If Not rg Is Nothing Then
    MsgBox "找张三,部分匹配,查找值,按列:" & rg.Address
   End If
   Set rg = .Find(what:="张三",LookIn:=xlValues, _
    lookat:=xlPart, MatchCase:=False, _
    MatchByte:=False, searchorder:=xlByRows)
   If Not rg Is Nothing Then
    MsgBox "找张三,部分匹配,查找值,按行:" & rg.Address
   End If
   
   'SearchDirection参数,搜索方向
   Set rg = .Find(what:="张三峰",LookIn:=xlFormulas, _
    lookat:=xlPart, _
    MatchCase:=False, MatchByte:=False, _
    searchorder:=xlByRows, SearchDirection:=xlNext)
   If Not rg Is Nothing Then
    MsgBox "找张三,按行,顺序查找:" & rg.Address
   End If
   Set rg = .Find(what:="张三峰",LookIn:=xlFormulas, _
    lookat:=xlPart, MatchCase:=False, MatchByte:=False, _
    searchorder:=xlByColumns, SearchDirection:=xlPrevious)
   If Not rg Is Nothing Then
    MsgBox "找张三,按列,逆序查找:" & rg.Address
   End If
   '注意结果为什么不是C7
   Set rg = .Find(what:="张三峰",LookIn:=xlFormulas, _
    lookat:=xlPart, searchorder:=xlByRows, _
    SearchDirection:=xlPrevious)
   If Not rg Is Nothing Then
    MsgBox "找张三,逆序,按行:" & rg.Address
   End If
   '与上面按行查找对比


   'matchcase参数,大小写问题
   Set rg = .Find(what:="ab", LookIn:=xlFormulas, _
    lookat:=xlPart, MatchCase:=False, MatchByte:=True, _
    searchorder:=xlByRows, SearchDirection:=xlNext)
   If Not rg Is Nothing Then
    MsgBox "ab,不区分大小写,区分全半角:" & rg.Address
   End If
   Set rg = .Find(what:="ab", LookIn:=xlFormulas, _
    lookat:=xlPart, MatchCase:=True, MatchByte:=True, _
    searchorder:=xlByColumns, SearchDirection:=xlNext)
   If Not rg Is Nothing Then
    MsgBox "ab,区分大小写:" & rg.Address
   End If


   'MatchByte参数,区分全角半角
   Set rg = .Find(what:="AB", LookIn:=xlFormulas, lookat:=xlPart,_
    MatchCase:=False, MatchByte:=False, _
    searchorder:=xlColumns, SearchDirection:=xlNext)
   If Not rg Is Nothing Then
    MsgBox "AB,不区分大小写与全半角:" & rg.Address
   End If
   Set rg = .Find(what:="ab", LookIn:=xlFormulas, lookat:=xlPart,_
    MatchCase:=False, MatchByte:=True, _
    searchorder:=xlByColumns, SearchDirection:=xlNext)
   If Not rg Is Nothing Then
    MsgBox "ab,区分全角半角:" & rg.Address
   End If
  End With
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2014-1-9 08:32 | 显示全部楼层
回复

使用道具 举报

发表于 2014-6-11 16:29 | 显示全部楼层
回复

使用道具 举报

发表于 2014-6-18 12:39 | 显示全部楼层
回复

使用道具 举报

发表于 2014-6-27 08:13 | 显示全部楼层
谢谢分享,标记,七十四
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-2 21:33 , Processed in 0.226330 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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