#1
|
|||
|
|||
Advance one hour
Good morning, I have some time slots, and I need to advance one hour to the whole time slot, I have tried several things without success. There is some way forward for an hour at all times as they are different. I attach an example. Attached example marked in green is the expected result. Thank you. |
#2
|
|||
|
|||
Give this a shot...
Code:
Sub AdvanceTimes() Dim tmp, cel As Range Dim firstTime As String Dim secondTime As String With Sheets("Sheet1") For Each cel In .Range("B3:C25") tmp = Split(cel.Value, "-") firstTime = CStr(Format(DateAdd("h", 1, CDate(tmp(0))), "hh:mm")) secondTime = CStr(Format(DateAdd("h", 1, CDate(tmp(1))), "hh:mm")) cel.Value = firstTime & "-" & secondTime Next cel End With End Sub |
#3
|
|||
|
|||
Thank you very much, it works perfectly. A doubt only, if there is some text in the schedule like for example vacations, appears error 13. Is there any way to solve it? Thank you very much for your help.
|
#4
|
|||
|
|||
Quote:
Provided none of your 'for example vacations' have a colon at the third character position this should do it. Code:
Sub AdvanceTimes_v2() Dim tmp, cel As Range Dim firstTime As String Dim secondTime As String With Sheets("Sheet1") For Each cel In .Range("B3:C25") If InStr(Trim(cel.Value), ":") = 3 Then tmp = Split(cel.Value, "-") firstTime = CStr(Format(DateAdd("h", 1, CDate(tmp(0))), "hh:mm")) secondTime = CStr(Format(DateAdd("h", 1, CDate(tmp(1))), "hh:mm")) cel.Value = firstTime & "-" & secondTime End If Next cel End With End Sub |
#5
|
||||
|
||||
Do not crosspost your question on multiple forums without including links here to the other threads on other forums.
Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post. We are here to help so help us to help you! Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post |
#6
|
|||
|
|||
NoSparks thank you very much for your help, it works very well. It's fixed. Pecoflyer I apologize for cross-posts, in the other forum I had not received an answer, that's the reason I opened it in this forum. He does not know the rules. I already know them and will not happen again.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Getting difference in time as a decimal and percentage of an hour | shabbaranks | Excel | 2 | 05-23-2017 07:22 AM |
24 hour task calendar doesn't show a day?? | benl | Project | 3 | 12-31-2015 02:55 PM |
12 hour work days (shifts) | John Franklin | Project | 22 | 11-12-2013 03:19 PM |
Can Excel Deduct 30 Minutes from an 8 1/2 Hour Cell? | tatihulot | Excel | 4 | 05-16-2013 04:30 PM |
Half hour added between tasks | maruchi | Project | 1 | 06-17-2010 08:06 AM |