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 |
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 |
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 |
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 |
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 - |
All times are GMT +1. The time now is 02:05 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com