Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Cell Contents =today() then....
I'm trying to write a macro where if the date in cell A1 is the same as
today's date then the macro ends but if the cell is blank or has any other date then it puts today's date in cell F2 The code is below but it isn't recognising where the date in A1 is the same as today's - it continues to put today's date in F2. I'm not sure what I've done wrong but I've tried a number of variations on a theme without success so I'm stuck and would really appreciate some help. Thanks a lot ------------- Sub hats() Range("a1").Select If ActiveCell.Value = "=today()" Then End ElseIf ActiveCell.Value < "=today()" Then Range("F2").Select ActiveCell.FormulaR1C1 = "=today()" Selection.Copy Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False ActiveSheet.Paste Application.CutCopyMode = False End If End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Cell Contents =today() then....
Try
ActiveCell.Formula = "=today()" or ActiveCell.Value = Today Cheers Darren On Oct 25, 10:44 am, nospaminlich wrote: I'm trying to write a macro where if the date in cell A1 is the same as today's date then the macro ends but if the cell is blank or has any other date then it puts today's date in cell F2 The code is below but it isn't recognising where the date in A1 is the same as today's - it continues to put today's date in F2. I'm not sure what I've done wrong but I've tried a number of variations on a theme without success so I'm stuck and would really appreciate some help. Thanks a lot ------------- Sub hats() Range("a1").Select If ActiveCell.Value = "=today()" Then End ElseIf ActiveCell.Value < "=today()" Then Range("F2").Select ActiveCell.FormulaR1C1 = "=today()" Selection.Copy Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False ActiveSheet.Paste Application.CutCopyMode = False End If End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Cell Contents =today() then....
You seem to have made your sub unnecessarily complicated.
This sub will compare the date in cell A1 with the current date and if they don't match it will enter the current date and time in cell f2. Sub hats() Range("a1").Select If DatePart("y", ActiveCell.Value) < DatePart("y", Now()) Then Range("F2").Select Selection.Value = Now() End If End Sub HTH Andy W "nospaminlich" wrote: I'm trying to write a macro where if the date in cell A1 is the same as today's date then the macro ends but if the cell is blank or has any other date then it puts today's date in cell F2 The code is below but it isn't recognising where the date in A1 is the same as today's - it continues to put today's date in F2. I'm not sure what I've done wrong but I've tried a number of variations on a theme without success so I'm stuck and would really appreciate some help. Thanks a lot ------------- Sub hats() Range("a1").Select If ActiveCell.Value = "=today()" Then End ElseIf ActiveCell.Value < "=today()" Then Range("F2").Select ActiveCell.FormulaR1C1 = "=today()" Selection.Copy Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False ActiveSheet.Paste Application.CutCopyMode = False End If End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Cell Contents =today() then....
Typo, VBA is Date not Today
-- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "darrenmcconachie" wrote in message oups.com... Try ActiveCell.Formula = "=today()" or ActiveCell.Value = Today Cheers Darren On Oct 25, 10:44 am, nospaminlich wrote: I'm trying to write a macro where if the date in cell A1 is the same as today's date then the macro ends but if the cell is blank or has any other date then it puts today's date in cell F2 The code is below but it isn't recognising where the date in A1 is the same as today's - it continues to put today's date in F2. I'm not sure what I've done wrong but I've tried a number of variations on a theme without success so I'm stuck and would really appreciate some help. Thanks a lot ------------- Sub hats() Range("a1").Select If ActiveCell.Value = "=today()" Then End ElseIf ActiveCell.Value < "=today()" Then Range("F2").Select ActiveCell.FormulaR1C1 = "=today()" Selection.Copy Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False ActiveSheet.Paste Application.CutCopyMode = False End If End Sub |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Cell Contents =today() then....
Course it is. Silly me!!
Typo, VBA is Date not Today On Oct 25, 12:25 pm, "Bob Phillips" wrote: -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "darrenmcconachie" wrote in ooglegroups.com... Try ActiveCell.Formula = "=today()" or ActiveCell.Value = Today Cheers Darren On Oct 25, 10:44 am, nospaminlich wrote: I'm trying to write a macro where if the date in cell A1 is the same as today's date then the macro ends but if the cell is blank or has any other date then it puts today's date in cell F2 The code is below but it isn't recognising where the date in A1 is the same as today's - it continues to put today's date in F2. I'm not sure what I've done wrong but I've tried a number of variations on a theme without success so I'm stuck and would really appreciate some help. Thanks a lot ------------- Sub hats() Range("a1").Select If ActiveCell.Value = "=today()" Then End ElseIf ActiveCell.Value < "=today()" Then Range("F2").Select ActiveCell.FormulaR1C1 = "=today()" Selection.Copy Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False ActiveSheet.Paste Application.CutCopyMode = False End If End Sub- Hide quoted text -- Show quoted text - |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
concatenate contents of cells whose contents resemble cell referem | Excel Worksheet Functions | |||
IF TODAY equals date in cell A10, or if TODAY is beyond that date | Excel Worksheet Functions | |||
Macro to clear range contents when cell contents are changed by us | Excel Programming | |||
Macro to remove contents of cell and move all other contents up one row | Excel Discussion (Misc queries) | |||
Copying cell contents to add to existing contents in another cell | Excel Programming |