Colour unique formulae and constant cells of all sheets of activeworkbook

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

你可能感兴趣的:(PHP)