|
楼主 |
发表于 2019-1-24 13:49
|
显示全部楼层
本帖最后由 冬日暖暖 于 2019-1-25 14:53 编辑
根据以上两位提供的解答,我更新的代码,执行结果和期望一致。
Sub application_find_color()
Dim Rng, U_Rng, Temp_Rng As Range
Dim st_Rng As String
Application.FindFormat.Clear
Application.FindFormat.Font.ColorIndex = 3
Set Rng = Cells.Find(What:="*", LookIn:=xlValues, searchformat:=True)
If Rng Is Nothing Then MsgBox "没有找到符合条件的单元格": Exit Sub '判断查找结果是否为空,如果为空则退出程序。
st_Rng = Rng.Address
Set U_Rng = Rng
For Each Temp_Rng In Sheet2.UsedRange
Set Rng = Cells.Find(What:="*", After:=Rng, LookIn:=xlValues, searchformat:=True)
If Rng.Address <> st_Rng Then
Set U_Rng = Application.Union(U_Rng, Rng)
Else
Exit For
End If
Next
U_Rng.Interior.ColorIndex = 4
End Sub
|
|