Colour unique formulae and constant cells of all sheets of activeworkbook

来源:互联网 发布:微观经济数据 编辑:程序博客网 时间:2024/06/10 14:48

A question in http://www.mrexcel.com/board2/viewtopic.php?t=304750

I am looking for a macro which does two things:

1. colours all constants in a workbook as yellow.

2. colours all formulae with purple but I don't want the formulae which are copies to be coloured (i.e. the ones which are copied across columns or copied down in rows).

is there any way of doing this?  

----------------------------------------------------

My answer:

Sub Addbackcolor()
Dim sh As Worksheet, d As Object, r As Range
Set d = CreateObject("scripting.dictionary")
For Each sh In Sheets
d.RemoveAll
For Each r In sh.Cells.SpecialCells(xlCellTypeFormulas, 23)
If Not d.exists(r.FormulaR1C1) Then d.Add r.FormulaR1C1, r.Address
Next
sh.Range(Join(d.items, ",")).Interior.Color = &HFF99CC
sh.Cells.SpecialCells(xlCellTypeConstants, 23).Interior.Color = vbYellow
Next
Set d = Nothing
End Sub

原创粉丝点击