Martu Theophilus
New Member
- Joined
- Apr 16, 2020
- Messages
- 8
- Office Version
- 2010
- Platform
- Windows
Dear Experts,
Could you please help me to repair my macro in VBA. The aim is to put in a column R the time difference in days ( can also show hours) between later date stamp column M and the first date stamp in column B. The macro attached below works and calculates the difference in days, however it runs the macro till the end of the column R. returning the value of 0, even when columns B and M are empty. I would like the calculation only to be done when there is a value in the time stamp cells in column B and M.
I would be grateful for yours suggestions.
Kind regards
Martek
I have tried with .End(xlUp) however the loop is stopped and column r does not show any data -
the time difference calculation does not work anymore....... Any ideas which formula is the best to simply calculate the difference between two date stamps.
Thank you
M
Could you please help me to repair my macro in VBA. The aim is to put in a column R the time difference in days ( can also show hours) between later date stamp column M and the first date stamp in column B. The macro attached below works and calculates the difference in days, however it runs the macro till the end of the column R. returning the value of 0, even when columns B and M are empty. I would like the calculation only to be done when there is a value in the time stamp cells in column B and M.
I would be grateful for yours suggestions.
Kind regards
Martek
VBA Code:
Sub datediff()
With Range("R12:R" & Range("B" & Rows.Count).End(xlDown).Row)
.FormulaR1C1 = "=datedif(rc[-16],rc[-5],""d"")"
Dim x As Integer
Application.ScreenUpdating = False
' Set numrows = number of rows of data.
' Establish "For" loop to loop "numrows" number of times.
' Insert your code here.
' Selects cell down 1 row from active cell.
End With
End Sub
I have tried with .End(xlUp) however the loop is stopped and column r does not show any data -
the time difference calculation does not work anymore....... Any ideas which formula is the best to simply calculate the difference between two date stamps.
Thank you
M
Attachments
Last edited by a moderator: