VBA代码集锦-Find方法(4)-查找特定格式的单元格
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
VBA代码集锦-Find方法(4)-查找特定格式的单元格
一、代码示例
Sub FindWithFormat2()
With Application.FindFormat.Font
.Name = "黑体"
.ColorIndex = 3
.Size = 12
End With
Cells.Find(what:="*", searchformat:=True).Activate
Selection.Interior.ColorIndex = 5
MRG = Selection.Address
Do
Cells.Find(what:="*", After:=ActiveCell, searchformat:=True).Activate
aaa = Selection.Address
Selection.Interior.ColorIndex = 5
Loop Until MRG = aaa
End Sub
二、代码解析
Sub FindWithFormat2()
'本示例在当前工作表单元格中查找字体为”黑体”且字体颜色为红色,字号为12的非空单元格。
'其中,Application.FindFormat对象允许指定所需要查找的格式,此时Find方法的参数SearchFormat应设置为True。
With Application.FindFormat.Font
.Name = "黑体" '字体
.ColorIndex = 3 '字体颜色
.Size = 12 '字号
End With
Cells.Find(what:="*", searchformat:=True).Activate'激活符合条件的单元格
Selection.Interior.ColorIndex = 5 '单元格底色填充为蓝色
MRG = Selection.Address '记录单元格地址
'开始循环查找
Do
Cells.Find(what:="*", After:=ActiveCell, searchformat:=True).Activate
'激活符合条件的单元格
aaa = Selection.Address '记录单元格地址
Selection.Interior.ColorIndex = 5 '单元格底色填充为蓝色
'其他处理方式
Loop Until MRG = aaa '查找到与第一个符合条件的单元格地址相同时停止
End Sub
----------------------------------------。