Adding X amount of hours to Date Time Field

excelnube

Board Regular
Joined
Jul 14, 2011
Messages
65
Hi guys,

I think this is a fairly simple issue, or so i hope.

Column D of my spreadsheet, contains between 400-500+ records in format: dd\/mm\/yyyy hh\:mm

What i would like to do is write a piece of VBA code that loops through the values in Column D, and add a specified amount of time to it.

The specified amount of time is stored Sheet2 E2 of the current workbook - for example 5:30 hours.

So, if i had an original date time of 09/11/2012 10:00, the new value would be 09/11/2012 15:30.

Any help appreciated.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try

Code:
Sub atest()
Dim LR As Long, i As Long
LR = Range("D" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    With Range("D" & i)
        .Value = .Value + Sheets("Sheet2").Range("E2").Value
    End With
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,929
Members
449,479
Latest member
nana abanyin

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