Extract hours from a string text.

jrschenck

New Member
Joined
Mar 9, 2016
Messages
4
Hello. I'm trying to add the hours in a schedule created in an excel spreadsheet. The information is formatted as "8am to 5pm" in each cell (varies of course depending in the individuals schedule). What I would like to do is translate anything with a "pm" into a 2400 format and then subtract the smaller number to get the total hours (ie 5pm becomes 1700, 8am becomes 800). I want to add up the hours of each day for the whole week but I think once I understand how to pull the hours per cell I can figure out how to do an array. Is there any suggestions for this?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This is just a general comment:

I hope you have some controls in place to prevent users from "free forming" the data entry.
I'm thinking of preventing entries like the following:
8:15 a.m. thru 5 PM
9 to 5
etc
 
Upvote 0
Ron, I realize that would be easier, but this is a table that I inherited. It is what it is. I don't have a lot of control over it and doubt if I can retrain the people to input differently. I can calculate this in my head, but thought it would be an interesting challenge to see if I can write a program that will strip the numbers, calculate the hours and eventually add them up for the week. However I don't have a lot of time to put into this and need some help to get started. Thank you.
 
Upvote 0
Ron, I realize that would be easier, but this is a table that I inherited. It is what it is. I don't have a lot of control over it and doubt if I can retrain the people to input differently. I can calculate this in my head, but thought it would be an interesting challenge to see if I can write a program that will strip the numbers, calculate the hours and eventually add them up for the week. However I don't have a lot of time to put into this and need some help to get started. Thank you.
 
Upvote 0
The optimal situation would be to change the input tab so it has controls on what is allowable (maybe a data validation).
If that can't be done, we'll need samples of every kind of format that you plan on parsing.
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top