Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I recorded a macro that inputs the current time. The user will click in the
"Start Time" cell and run the macro, then when the user is finished he will click in the "End Time" and run the macro again. What I want to do is make sure the user does not run the macro in a cell that is not blank. I'm afraid that the user will attempt to run the macro in a cell that already has a value. I was thinking that an If statement, to determine if the is cell is not blank would work. T.I.A. Ed Sub Now_1() ' ' Now_1 Macro ' ' ' ActiveCell.FormulaR1C1 = "=NOW()" Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ed,
Try something like If Range("StartTime").Value = "" Then Range("StartTime").Value = Now End If -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Ed" wrote in message ... I recorded a macro that inputs the current time. The user will click in the "Start Time" cell and run the macro, then when the user is finished he will click in the "End Time" and run the macro again. What I want to do is make sure the user does not run the macro in a cell that is not blank. I'm afraid that the user will attempt to run the macro in a cell that already has a value. I was thinking that an If statement, to determine if the is cell is not blank would work. T.I.A. Ed Sub Now_1() ' ' Now_1 Macro ' ' ' ActiveCell.FormulaR1C1 = "=NOW()" Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub Now_1()
' ' Now_1 Macro ' ' ' if Isempty(activecell) then activeCell.Value = now ' vba NOW function Else msgbox "The cell already contains a value" End if End Sub You don't need to put in a formula then convert it to a value. If you want to go that route however: Sub Now_1() ' ' Now_1 Macro ' ' ' if Isempty(activecell) then activeCell.Formula = "=now()" activeCell.Formula = ActiveCell.Value Else msgbox "The cell already contains a value" End if End Sub -- Regards, Tom Ogilvy "Ed" wrote in message ... I recorded a macro that inputs the current time. The user will click in the "Start Time" cell and run the macro, then when the user is finished he will click in the "End Time" and run the macro again. What I want to do is make sure the user does not run the macro in a cell that is not blank. I'm afraid that the user will attempt to run the macro in a cell that already has a value. I was thinking that an If statement, to determine if the is cell is not blank would work. T.I.A. Ed Sub Now_1() ' ' Now_1 Macro ' ' ' ActiveCell.FormulaR1C1 = "=NOW()" Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False End Sub |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Ed,
Sub Now_1() With ActiveCell If .Value = "" Then .Value = Now Else MsgBox "Already filled" End If End With End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Ed" wrote in message ... I recorded a macro that inputs the current time. The user will click in the "Start Time" cell and run the macro, then when the user is finished he will click in the "End Time" and run the macro again. What I want to do is make sure the user does not run the macro in a cell that is not blank. I'm afraid that the user will attempt to run the macro in a cell that already has a value. I was thinking that an If statement, to determine if the is cell is not blank would work. T.I.A. Ed Sub Now_1() ' ' Now_1 Macro ' ' ' ActiveCell.FormulaR1C1 = "=NOW()" Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
IF statement inside a SUMIF statement.... or alternative method | Excel Worksheet Functions | |||
Reconcile Bank statement & Credit card statement & accounting data | Excel Worksheet Functions | |||
Embedding an OR statement in an IF statement efficiently | Excel Discussion (Misc queries) | |||
Sum if statement with a left statement | Excel Discussion (Misc queries) | |||
appending and IF statement to an existing IF statement | Excel Worksheet Functions |