Share via

how to decrease time value by one hour

Anonymous
2024-11-02T19:53:31+00:00

Hello

In range A1 -A10 i have time value like 6:28:40 and i would like to decrease the hour by 1 to get 5:28:40

I tried the following macro

Sub test()

Dim i As Integer

For i = 1 To 10

Range("A" & i).Value = Range("A" & i).Value - Time(1, 0, 0)

Next i

End Sub

but i get an error type mismatch

thanks

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2024-11-02T20:06:39+00:00

VBA uses TimeSerial instead of Time:

Range("A" & i).Value = Range("A" & i).Value - TimeSerial(1, 0, 0)

(Time returns the current time in VBA)

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful