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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You could trim it down to:
Code:
Sub macro1()
Range("L1") = Format(Now(), "hh:mm:ss ampm")
Range("L9").Select
End Sub
 
Upvote 0
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?
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,887
Members
449,057
Latest member
Moo4247

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
Back
Top