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

Flexcel22

Board Regular
Joined
Apr 8, 2016
Messages
52
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?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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,
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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