Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default If Statement Help

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default If Statement Help

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default If Statement Help

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default If Statement Help

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
Sum if statement with a left statement Eric D Excel Discussion (Misc queries) 4 July 23rd 08 05:31 PM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM


All times are GMT +1. The time now is 03:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"