View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
blopreste3180
 
Posts: n/a
Default HOW DO YOU INSERT A MACRO INTO A FORMULA

I keep getting a Compile Error: Expected: = then it highlights the <= portion
of your code. Any suggestions?

"William Horton" wrote:

Put this code in the worksheet section. It assumes the worksheet you are
working from is Sheet1, the target date is in cell A2, and the name that you
want the font to change is in cell A11. Make any adjustments to the code as
needed.

Private Sub Worksheet_Activate()
Dim Target As Date
If IsDate(ThisWorkbook.Worksheets("Sheet1").Range("A2 ").Value) Then
Target = ThisWorkbook.Worksheets("Sheet1").Range("A2").Valu e
If DateDiff("d", Date, Target) <= 30 Then
ThisWorkbook.Worksheets("Sheet1").Range("A11").Fon t.Color = 255
End If
End If
ThisWorkbook.Worksheets("Sheet1").Range("A11").Act ivate
End Sub

A conditional format would work too.

Bill Horton

"blopreste3180" wrote:

I am trying to insert a macro based on a "If" formula that will highlight a
specific cell or range of cells in a worksheet to a particular color. For
example, if todays date is 30 days or less from a target date, then I want a
name on a particular sheet to turn red to let me know to do something. Any
help is appreciated.