Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Split "9:00 - 5:30pm" to "9:00" "17:30"

The times in a roster are shown in the following way:

9:00 - 5:30pm



I need to copy these times to a timesheet and split the start and finish
times into separate cells.



Like this:



If Worksheet("Sheet1").Range("A1") .value = "9:00 - 5:30pm" then

Worksheet("Sheet2").Range("A1") .value = "9:00"

Worksheet("Sheet2").Range("B1") .value = "17:30"

End if



But the start and finish times can be anything. They may be "10:00 - 8:30pm"
etc etc.










  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Split "9:00 - 5:30pm" to "9:00" "17:30"

Lucas,

Sub TryNow()
Dim myStr As String
Dim myCell As Range

On Error Resume Next
For Each myCell In Worksheets("Sheet1").Range("A1:A10")

myStr = myCell.Value
If myStr < "" Then
Worksheets("Sheet2").Range("A" & myCell.Row).Value = _
TimeValue(Left(myStr, _
InStr(1, myStr, " ") - 1))
Worksheets("Sheet2").Range("B" & myCell.Row).Value = _
TimeValue(Mid(myStr, _
InStr(1, myStr, " - ") + 3, 200))
End If
Next myCell

End Sub


HTH,
Bernie
MS Excel MVP


"Lucas Budlong" wrote in message
...
The times in a roster are shown in the following way:

9:00 - 5:30pm



I need to copy these times to a timesheet and split the start and finish times into separate
cells.



Like this:



If Worksheet("Sheet1").Range("A1") .value = "9:00 - 5:30pm" then

Worksheet("Sheet2").Range("A1") .value = "9:00"

Worksheet("Sheet2").Range("B1") .value = "17:30"

End if



But the start and finish times can be anything. They may be "10:00 - 8:30pm" etc etc.












  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Split "9:00 - 5:30pm" to "9:00" "17:30"

Have you tried doing a text to columns. Set the "-" as the delimiter and it
will split the text into two times. The times can be formatted however you
like using standard Excel formatting...
--
HTH...

Jim Thomlinson


"Lucas Budlong" wrote:

The times in a roster are shown in the following way:

9:00 - 5:30pm



I need to copy these times to a timesheet and split the start and finish
times into separate cells.



Like this:



If Worksheet("Sheet1").Range("A1") .value = "9:00 - 5:30pm" then

Worksheet("Sheet2").Range("A1") .value = "9:00"

Worksheet("Sheet2").Range("B1") .value = "17:30"

End if



But the start and finish times can be anything. They may be "10:00 - 8:30pm"
etc etc.











  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Split "9:00 - 5:30pm" to "9:00" "17:30"

Thanks Bernie,
That's perfect!!!
L.

Bernie Deitrick wrote:
Lucas,

Sub TryNow()
Dim myStr As String
Dim myCell As Range

On Error Resume Next
For Each myCell In Worksheets("Sheet1").Range("A1:A10")

myStr = myCell.Value
If myStr < "" Then
Worksheets("Sheet2").Range("A" & myCell.Row).Value = _
TimeValue(Left(myStr, _
InStr(1, myStr, " ") - 1))
Worksheets("Sheet2").Range("B" & myCell.Row).Value = _
TimeValue(Mid(myStr, _
InStr(1, myStr, " - ") + 3, 200))
End If
Next myCell

End Sub


HTH,
Bernie
MS Excel MVP


"Lucas Budlong" wrote in message
...
The times in a roster are shown in the following way:

9:00 - 5:30pm



I need to copy these times to a timesheet and split the start and finish times into separate
cells.



Like this:



If Worksheet("Sheet1").Range("A1") .value = "9:00 - 5:30pm" then

Worksheet("Sheet2").Range("A1") .value = "9:00"

Worksheet("Sheet2").Range("B1") .value = "17:30"

End if



But the start and finish times can be anything. They may be "10:00 - 8:30pm" etc etc.











Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
How do I split "A1B2" into "A1" and "B2" using text to column fun. Jennifer Excel Programming 1 February 2nd 05 10:01 PM


All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"