Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 115
Default Converting time-formatted to text-based data

I'm setting up several thousand contract names for a workforce management
program from time-formatted data in Excel and am hoping there might be a way
using a VB script to look up the value of a cell and convert it to form part
of the unique name given to that contract.

Example: the data running from Sunday start attendance to Saturday end
attendance is contained in, say, cells: c110-p110

00:00 00:00 08:00 16:00 08:00 16:30 08:00 16:30 08:00 16:00 08:00 16:00 00:00 00:00

The standard part of the contract name I need to generate is: "FT NR 36",
followed by:

M (8h-16h),Tu (8h-16h30), W (8h-16h30), Th (8h-16h), F (8h-16h)

The 00:00 values in start end of first 2 cells (Sunday) c110 & d110 and last
2 cells (Saturday) o110 & p110 should return no values in the heading, as
shown above. If there was data in these cells it should return S(start-end
hrs) and Sa (start-end hrs) in the same format as the Mon-Fri attendances
shown above.

Many thanks for any advice




  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Converting time-formatted to text-based data

Try this code

Sub contractname()

DNames = Array("M", "Tu", "W", "Th", "F")
RowNum = 110
Contract = "FT NR 36"
CName = Contract
DayIndex = 0
For ColCount = Range("C" & RowNum).Column To _
Range("P" & RowNum).Column Step 2

StartHour = Hour(Cells(RowNum, ColCount))
StartMinute = Minute(Cells(RowNum, ColCount))
EndHour = Hour(Cells(RowNum, ColCount + 1))
EndMinute = Minute(Cells(RowNum, ColCount + 1))

CHours = DNames(DayIndex) & " (" & StartHour & "H"
If StartMinute < 0 Then
CHours = CHours & Format(StartMinute, "#00")
End If

CHours = CHours & "-" & Format(EndHour & "H", "#00")
If EndMinute < 0 Then
CHours = CHours & EndMinute
End If
CHours = CHours & ")"

CName = CName & "," & CHours
DayIndex = DayIndex + 1
Next ColCount

End Sub


"Zakynthos" wrote:

I'm setting up several thousand contract names for a workforce management
program from time-formatted data in Excel and am hoping there might be a way
using a VB script to look up the value of a cell and convert it to form part
of the unique name given to that contract.

Example: the data running from Sunday start attendance to Saturday end
attendance is contained in, say, cells: c110-p110

00:00 00:00 08:00 16:00 08:00 16:30 08:00 16:30 08:00 16:00 08:00 16:00 00:00 00:00

The standard part of the contract name I need to generate is: "FT NR 36",
followed by:

M (8h-16h),Tu (8h-16h30), W (8h-16h30), Th (8h-16h), F (8h-16h)

The 00:00 values in start end of first 2 cells (Sunday) c110 & d110 and last
2 cells (Saturday) o110 & p110 should return no values in the heading, as
shown above. If there was data in these cells it should return S(start-end
hrs) and Sa (start-end hrs) in the same format as the Mon-Fri attendances
shown above.

Many thanks for any advice




  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 115
Default Converting time-formatted to text-based data

Joel,

That's great - thank you! - I'll certainly give it a try.

best wishes,

"Zakynthos"

"Joel" wrote:

Try this code

Sub contractname()

DNames = Array("M", "Tu", "W", "Th", "F")
RowNum = 110
Contract = "FT NR 36"
CName = Contract
DayIndex = 0
For ColCount = Range("C" & RowNum).Column To _
Range("P" & RowNum).Column Step 2

StartHour = Hour(Cells(RowNum, ColCount))
StartMinute = Minute(Cells(RowNum, ColCount))
EndHour = Hour(Cells(RowNum, ColCount + 1))
EndMinute = Minute(Cells(RowNum, ColCount + 1))

CHours = DNames(DayIndex) & " (" & StartHour & "H"
If StartMinute < 0 Then
CHours = CHours & Format(StartMinute, "#00")
End If

CHours = CHours & "-" & Format(EndHour & "H", "#00")
If EndMinute < 0 Then
CHours = CHours & EndMinute
End If
CHours = CHours & ")"

CName = CName & "," & CHours
DayIndex = DayIndex + 1
Next ColCount

End Sub


"Zakynthos" wrote:

I'm setting up several thousand contract names for a workforce management
program from time-formatted data in Excel and am hoping there might be a way
using a VB script to look up the value of a cell and convert it to form part
of the unique name given to that contract.

Example: the data running from Sunday start attendance to Saturday end
attendance is contained in, say, cells: c110-p110

00:00 00:00 08:00 16:00 08:00 16:30 08:00 16:30 08:00 16:00 08:00 16:00 00:00 00:00

The standard part of the contract name I need to generate is: "FT NR 36",
followed by:

M (8h-16h),Tu (8h-16h30), W (8h-16h30), Th (8h-16h), F (8h-16h)

The 00:00 values in start end of first 2 cells (Sunday) c110 & d110 and last
2 cells (Saturday) o110 & p110 should return no values in the heading, as
shown above. If there was data in these cells it should return S(start-end
hrs) and Sa (start-end hrs) in the same format as the Mon-Fri attendances
shown above.

Many thanks for any advice




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
Converting formatted text into a txt file Marc Excel Discussion (Misc queries) 1 June 21st 07 04:00 PM
How do I add text to worksheet page based on intuitive formatted d Britt Excel Worksheet Functions 2 March 28th 07 01:52 AM
converting a number to time formatted as minutes JR Excel Worksheet Functions 2 February 9th 06 07:31 PM
Converting numbers formatted as text to numbers Bill Excel Discussion (Misc queries) 1 July 19th 05 07:10 PM
Converting 'General' formatted cells to Text formatted cell using. Zahid Khan Excel Worksheet Functions 1 March 12th 05 07:13 PM


All times are GMT +1. The time now is 12:54 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"