|
本帖最后由 zhaogang1960 于 2013-12-19 17:32 编辑
这个题目可以用Find方法查出符合条件的所有单元格,并删除文本及底色,并检查该单元格有没有图片,如果有则删除:- Sub 宏1()
- Dim c As Range, rng As Range, firstAddress$, m&, d As Object, shp As Shape
- Set d = CreateObject("scripting.dictionary")
- With Application.FindFormat
- .Clear
- .Interior.Color = RGB(192, 192, 192)
- End With
- With ActiveSheet.UsedRange
- Set c = .Find(What:="", SearchFormat:=True)
- If Not c Is Nothing Then
- firstAddress = c.Address
- Do
- m = m + 1
- If m > 1 Then Set rng = Union(rng, c) Else Set rng = c
- d(c.Address) = ""
- Set c = .Find(What:="", After:=c, SearchFormat:=True)
- Loop While Not c Is Nothing And firstAddress <> c.Address
- End If
- End With
- If m > 0 Then
- rng.ClearContents'删除符合条件单元格的内容
- 'rng.Interior.ColorIndex = xlNone'这一句删除符合条件单元格的底色,如果要保留,请删除这一句
- For Each shp In ActiveSheet.Shapes'删除TopLeftCell单元格有特定底色的图片
- If d.Exists(shp.TopLeftCell.Address) Then shp.Delete
- Next
- End If
- End Sub
复制代码 |
|