小说网 找小说 无限小说 烟雨红尘 幻想小说 酷文学 深夜书屋

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

posted on 2007-12-06 00:16  王峰炬  阅读(97)  评论(0编辑  收藏  举报

导航