View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Leith Ross[_414_] Leith Ross[_414_] is offline
external usenet poster
 
Posts: 1
Default macro to insert formula if cell format criteria satisafied


Hello Los,

Here is an example. This runs through A1:A100 on Worksheet1 looking for
Red cells. When found a formula is inserted 2 columns to the right. You
can change the worksheet name, range and formula to match your needs.


Code:
--------------------

Public Sub AddFormula()

Dim Rng As Range
Dim Formula As String

Set Rng = Worksheets("Sheet1").Range("A1:A100")
Formula = "= 2+2"

For Each Cell In Rng
If Cell.Interior.ColorIndex = vbRed Then
Cell.Offset(0, 2).Formula = Formula
End If
Next Cell

End Sub

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


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=495687