VBA to Add or Subtract Hours from the Local Date and Time

Flexcel22

New Member
Joined
Apr 8, 2016
Messages
35
Hello Again Mr and Mrs Excel,

I had columns with Headings:

Local Date, Local Time, UTC Date and UTC Time and a lot more columns to the right which I am not really concerned about.

With a command button pressed, all the columns in a single row are filled from corresponding Textboxes in Userform1.

Here is a code that I worked with:


Code:
With ActiveCell            '(LastRow in column A) which get it value from a combobox e.g = 06/07/17 (dd/mm/yyyy)
                      .Offset(0,1) = TextBox1.Value
                      .Offset(0,2) = TextBox2.Value
                      .Offset(0,3) = ActiveCell - 14 hours                              'My Local Date is +14 hrs to UTC Date so I want to subtract to get UTC
                      .Offset(0,4) = ActiveCell.Offset(0,1) - 14 hours             'In this section I want to get a UTC Time
Any idea on how to subtract or add hours to current Date and Time?
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

RickXL

MrExcel MVP
Joined
Sep 9, 2013
Messages
4,314
Hi,

If your cells contain times then you should be able to add fractions of a day. So, to add 14 hours you would need to add 14/24 to the time.


Regards,
 

Watch MrExcel Video

Forum statistics

Threads
1,089,877
Messages
5,410,926
Members
403,335
Latest member
ddaveryos

This Week's Hot Topics

Top