SOLVED

Time Macros

%3CLINGO-SUB%20id%3D%22lingo-sub-2652282%22%20slang%3D%22en-US%22%3ETime%20Macros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2652282%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20create%20a%20time%20sheet%20kinda%20workbook.%20I%20am%20wanting%20to%20set%20it%20up%20that%20when%20you%20click%20a%20button%20it%20will%20enter%20the%20current%20time.%20I%20need%20multiple%20buttons%20to%20do%20this%20to%20enter%20breaks%2C%20lunch%2C%20etc.%20When%20I%20add%20macros%20for%20the%20time%2C%20clicking%20one%20button%20changes%20all%20the%20times.%20How%20can%20I%20fix%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2652282%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2652306%22%20slang%3D%22en-US%22%3ERe%3A%20Time%20Macros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2652306%22%20slang%3D%22en-US%22%3EPresumably%20you're%20entering%20the%20current%20time%20via%20the%20function%20NOW().%20One%20possible%20resolution%20is%20to%20include%20in%20the%20macro%20the%20instructions%20to%20copy%2C%20and%20then%20use%20Paste%20Special%20...%20Values%20and%20Number%20Formatting%20to%20replace%20the%20NOW()%20with%20the%20simple%20value%2C%20which%20won't%20be%20updated.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2652307%22%20slang%3D%22en-US%22%3ERe%3A%20Time%20Macros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2652307%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1129484%22%20target%3D%22_blank%22%3E%40Shylyn%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20provide%20the%20code%20of%20the%20macros%2C%20or%20preferably%2C%20attach%20a%20copy%20of%20the%20workbook%20without%20sensitive%20data.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2652312%22%20slang%3D%22en-US%22%3ERe%3A%20Time%20Macros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2652312%22%20slang%3D%22en-US%22%3EI%20am%20using%20the%20NOW()%20function.%20I%20am%20not%20copying%20it%20for%20the%20other%20buttons%2C%20I%20was%20adding%20it%20to%20each%20button%20individually.%20I%20tried%20the%20copy%2Fpaste%20and%20figured%20that%20was%20the%20issue.%20I%20will%20try%20the%20Paste%20special%20and%20see%20if%20that%20works.%20I%20know%20very%20little%20about%20macros%20and%20I%20am%20trying%20to%20replace%20a%20workbook%20for%20my%20job.%3C%2FLINGO-BODY%3E
New Contributor

I am trying to create a time sheet kinda workbook. I am wanting to set it up that when you click a button it will enter the current time. I need multiple buttons to do this to enter breaks, lunch, etc. When I add macros for the time, clicking one button changes all the times. How can I fix this?

7 Replies
Presumably you're entering the current time via the function NOW(). One possible resolution is to include in the macro the instructions to copy, and then use Paste Special ... Values and Number Formatting to replace the NOW() with the simple value, which won't be updated.

@Shylyn 

Please provide the code of the macros, or preferably, attach a copy of the workbook without sensitive data.

I am using the NOW() function. I am not copying it for the other buttons, I was adding it to each button individually. I tried the copy/paste and figured that was the issue. I will try the Paste special and see if that works. I know very little about macros and I am trying to replace a workbook for my job.
best response confirmed by Shylyn (New Contributor)
Solution

@Shylyn

Instead of setting the formula of a cell to "=NOW()", set its value to Now. For example:

 

Sub SetTime()
    Range("D2").Value = Now
End Sub

.

 

@Shylyn

 

It is not very clear to me exactly what you want.  ``It will enter the current time`` where?!   ``I need multiple buttons to do this to enter breaks, lunch, etc`` why?!

 

And finally:  ``Clicking one button changes all the times. How can I fix this?``  How?!  We cannot fix what we cannot see.

 

Without clarity, any answer that you get is probably GIGO.

 

In any case, you probably do not want to use Excel NOW or VBA Now directly.  The first is accurate to the 10 millisecond(!).  The second is accurate to the 1 second. 

 

That accuracy will probably screw up any time arithmetic that you might intend to do, which I presume should be accurate only to the 1 minute.

 

Any VBA solution should probably be of the form:

 

Sub mytime()
Selection = Format(Now, "h:m")
End Sub

 

and properly format the selected cell as you prefer.

 

Caveat:  Be wary of any proposed solution that involves multiple calls to Excel NOW or VBA Now; e.g. Timeserial(Hour(Now),Minute(Now),0).  The time value (Now) might change between calls, resulting in inconsistencies; but only intermittently (i.e. rarely), which will drive you nuts.

 

@Joe User Sorry I am new at using forums like this. I am not sure how to share the workbook so you cab see what i am tryingto accomplish

THANK YOU SO MUCH! This is working just like I need it to.