I am writing a macro in VBA. I have a loop that goes through a list of dates and every entry where the minute is 00,15.30.45
it copies the date and time into a new column. This is only part of the code I am working on so that is why it seems pointless at the moment. My trouble is I need to modify the time that is copied into the new column. I need the date to stay the same but the time must be modified so that:
hh:00 becomes hh-1:45
hh:15 becomes hh :00
hh:30 becomes hh :15
hh:45 becomes hh :30
I have below the current code that I have and everything works except obviously it does not modify the time because I just made that up to make sense of what I want to do. What code do I need to modify the hour and minute? Thanks!
Dim X As Integer
Range("A2").Select
NumRows = Range(Selection, Selection.End(xlDown)).Rows.Count
Range("A2").Select
For X = 2 To NumRows
If (Minute(ActiveCell.Value) = 0) Then
Range("D2").Value = ActiveCell.Value
Range("D2").NumberFormat = "YYYY-MM-DD HH-1:45"
ElseIf (Minute(ActiveCell.Value) = 15) Then
Range("D2").Value = ActiveCell.Value
Range("D2").NumberFormat = "YYYY-MM-DD HH:00"
ElseIf (Minute(ActiveCell.Value) = 30) Then
Range("D2").Value = ActiveCell.Value
Range("D2").NumberFormat = "YYYY-MM-DD HH:15"
ElseIf (Minute(ActiveCell.Value) = 45) Then
Range("D2").Value = ActiveCell.Value
Range("D2").NumberFormat = "YYYY-MM-DD HH:30"
End If
Selection.Offset(1, 0).Select
Next X