Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default numbers to time in same cell

I need to be able to type numbers into a cell and then have the cell return a
time. I have a sheet where I want the agent to be able to type in say 123p
and get 1:23pm in return.


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 751
Default numbers to time in same cell

On Mar 12, 6:38 pm, cpolley wrote:
I need to be able to type numbers into a cell and then have the cell return a
time. I have a sheet where I want the agent to be able to type in say 123p
and get 1:23pm in return.


The following event procedure will do what you want. Notice that the
IF in the second line tests, e.g. if the cell in question is in column
D (Target.column = 4), thus I don't know if it corresponds to the
range of cells which you want to demonstrate this behavior. This is a
worksheet event procedure, thus you will insert it in the code module
of the sheet where you want this to happen.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 4 Then
Application.EnableEvents = False
If Len(Target) = 4 Then
hr = Left(Target, 1)
mn = Mid(Target, 2, 2)
ap = Right(Target, 1)
Else
hr = Left(Target, 2)
mn = Mid(Target, 3, 2)
ap = Right(Target, 1)
End If
Target.Value = TimeValue(hr & ":" & mn & " " & ap)
NumberFormat = "h:mm AM/PM"
Application.EnableEvents = True
End If
End Sub

To install:
Go to the sheet. Right-click the sheet tab. Choose View Code... This
will take you to the VBA IDE. Paste the above code to the module
window.

Write back if you need instructions on how to limit the cell range for
which this will apply.

HTH
Kostis Vezerides

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2
Default numbers to time in same cell

Thank you so much! I would need it to apply to only cells A12 thru A32 if
possible. You've been a tremendous help, thank you!

"cpolley" wrote:

I need to be able to type numbers into a cell and then have the cell return a
time. I have a sheet where I want the agent to be able to type in say 123p
and get 1:23pm in return.


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 751
Default numbers to time in same cell

If so, then this is the modified code for these two cells:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Row = 12 And Target.Row <= 32 Then
Application.EnableEvents = False
If Len(Target) = 4 Then
hr = Left(Target, 1)
mn = Mid(Target, 2, 2)
ap = Right(Target, 1)
Else
hr = Left(Target, 2)
mn = Mid(Target, 3, 2)
ap = Right(Target, 1)
End If
Target.Value = TimeValue(hr & ":" & mn & " " & ap)
NumberFormat = "h:mm AM/PM"
Application.EnableEvents = True
End If
End Sub

Regards,
Kostis

On Mar 12, 7:55 pm, cpolley wrote:
Thank you so much! I would need it to apply to only cells A12 thru A32 if
possible. You've been a tremendous help, thank you!

"cpolley" wrote:
I need to be able to type numbers into a cell and then have the cell return a
time. I have a sheet where I want the agent to be able to type in say 123p
and get 1:23pm in return.



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
Adding numbers to a Time Formated cell Browner Excel Discussion (Misc queries) 2 June 20th 06 03:55 PM
Help! How do you get excel to find the x(changes daily, marked in a cell from another formula) highest numbers in a group of numbers and sum them up? C-Man23 Excel Worksheet Functions 1 January 9th 06 01:23 PM
numbers to time Jibba02 Excel Worksheet Functions 2 November 2nd 05 07:12 AM
How to make a cell hold numbers as a length of time in xcel? Randall Clark Excel Discussion (Misc queries) 2 August 22nd 05 06:43 PM
Adding time to date-time formatted cell tawtrey(remove this )@pacificfoods.com Excel Discussion (Misc queries) 4 August 12th 05 10:53 PM


All times are GMT +1. The time now is 01:11 AM.

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

About Us

"It's about Microsoft Excel"