Forum Discussion
Andrew_Hinson
Apr 18, 2023Brass Contributor
VBA - Insert current time PLUS one minute
Hi everyone, I'm really sorry; I keep asking questions on here but never actually respond to anyone else's queries. I'm still an absolute amateur and can't help myself let alone anyone else. So I...
Andrew_Hinson
Apr 18, 2023Brass Contributor
HansVogelaar thank you so much, again!
I tweaked the code a little (I have no idea with VBA! I just fiddled with what looked right such as the name of the macro) and I have it working!
Only thing is that it inputs the date as well as the time? I need it to just enter the time (plus 1) as hh:mm
I tried changing the word date to time but it just kept having a run error?
Can you advise what I need to do please?
Massive thank you.
HansVogelaar
Apr 18, 2023MVP
One option is to format the cell as hh:mm. The date part will still be present, but not shown in the cell:
Sub TimePlusOne
On Error Resume Next
With ActiveCell
.Value = DateAdd("n", 1, Now)
.NumberFormat = "hh:mm"
End With
End Sub
If you prefer to enter only the time in the cell:
Sub TimePlusOne()
Dim t As Date
On Error Resume Next
t = Now
With ActiveCell
.Value = DateAdd("n", 1, t - Int(t))
.NumberFormat = "hh:mm"
End With
End Sub- Andrew_HinsonApr 19, 2023Brass ContributorHans you are a genius!
Thank you so much 🙂
Can you recommend any books/videos that would be good for me to start learning VBA?- HansVogelaarApr 19, 2023MVP
You'll find a series of tutorials at Excel-Easy
If you'd like a book: Excel VBA Programming For Dummies (don't be put off by the title, it's a serious book).