just need the current time

ibschleime

New Member
Joined
Jan 21, 2005
Messages
4
Ok, I know I can use =now() to get the time and date, but I am working with timecards and need to calculate a labor percentage based on the current time. I am removing the date from =now() by copying the cell and pasting the value. Then I replaced the spaces between the date and time with a comma and split them into two cells so I could use only the time. It works when I do it manually, but the macro doesn't work. Can anyone help me?

Here is what I did:

Range("L1").Select
Selection.NumberFormat = "General"
ActiveCell.FormulaR1C1 = "=NOW()"
Range("L1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
Range("L1").Select
ActiveCell.Replace What:=" ", Replacement:=",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Find(What:=" ", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
Selection.TextToColumns Destination:=Range("L1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Columns("M:M").EntireColumn.AutoFit
Range("A1").Select
ActiveCell.FormulaR1C1 = "=RC[12]"
Range("A1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
Range("L1:M1").Select
Selection.ClearContents
Selection.NumberFormat = "General"
Range("L9").Select
End Sub

thanks!!! i need help!!! :rolleyes:
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

vconfused

Well-known Member
Joined
Jun 11, 2004
Messages
547
You could trim it down to:
Code:
Sub macro1()
Range("L1") = Format(Now(), "hh:mm:ss ampm")
Range("L9").Select
End Sub
 

ibschleime

New Member
Joined
Jan 21, 2005
Messages
4
thanks, but that did not work for me. I replaced my code with your code, but; no-go.

is there a formula for time without the date?
 

ibschleime

New Member
Joined
Jan 21, 2005
Messages
4
ok, i figured out the macro part. your format line was what i needed.

thank you so much! quick help, i like that.

ps... is ther a formula just for time?
 

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,456
Try:
ActiveCell.Value = Time

You can format to your desire.

Hope it helps,
Dan
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,972
Messages
5,767,402
Members
425,410
Latest member
SmittyT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top