writing Now() to a cell but hiding date format ?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
Office Version
  1. 365
Platform
  1. Windows
Hi,

when i write date/time to a cell like this:
Range("G2").Value = Now

it outputs like: 19/09/2018 01:32:24

which is correct but im wanting it to display time only. I need the date for various calculations so cant just use Time() function.
I can manually set format to hh:mm after writing to cell but wondering if it can be done with vba

so i need Now() to display 01:32 but still hold the date value (43362.0641666667) if that makes sense

thanks for any help
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try:

Code:
Range("G2").NumberFormat = "hh:mm"

your code works:
Range("G2").Value = Now
Range("G2").NumberFormat = "hh:mm"


but i get this when trying with worksheet_change event:
f8cadf05a5.png


im writing the time to cell with:

Code:
Range("G" & Target.Row).Value = Now()
    Range("G" & Target.Row).NumberFormat = "hh:mm"

the first line works
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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