INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Excel VBA Loop through time values in 30 min increments

Excel VBA Loop through time values in 30 min increments

(OP)
Hi Guys,

I am building a userform to deal with creating a rota. What I am wanting to do is let the user select a start and end time from a dropdown list then when they click a button it will populate the worksheet as follows

Person 1 start time = 08:00 end time = 09:00
Person 2 start time = 08:00 end time = 10:00

Columns Headings (these are times)
_______|08:00 | 08:30 | 09:00 | 09:30 | 10:00 | 10:30
Person 1|A | A | | | |
Person 2|A | A | A | A | |

What I am wanting to do is loop through the people then populate the worksheet for each 30 min time increment between the start and end time. My issue is I am not sure of loop through the times in 30 increments

So for person 2 I would have a loop like

CODE --> VBA

starttime = "08:00"
endtime = "10:00"

time = starttime 

while time not equal to endtime
   ' do code here to populate the sheet etc...
   time + 30mins
Loop 

Does anyone out there have any tips on how to achieve the looping through the time?

Many Thanks in advance

J.

Regards

J.

RE: Excel VBA Loop through time values in 30 min increments

Hi,

time is not a good variable, but...

CODE

time = time + TimeSerial(0,30,0) 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel VBA Loop through time values in 30 min increments

...also...

CODE

while time < endtime 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Excel VBA Loop through time values in 30 min increments

(OP)
Cheers Skip,

Once again you have saved the day.

Many Thanks

J.

Regards

J.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close