Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default Automatic time conversion in the SAME cell

Hi,

If I key in the time "9:00:00 AM" in cell A4 and press the enter key, I
wanted cell A4 to display "3:00:00 AM". If this is possible, please tell me
the detailed procedure.

For your information, "9:00:00 AM" is the U.S. time, once I entered the
time excel in cell A4 for example, it should automatically become "3:00:00
AM" in German time in the SAME A4 cell.

Thanks in advance.

Regards,
Megs
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Automatic time conversion in the SAME cell

One way:

Put this in your worksheet code module (right-click the worksheet tab
and choose View Code from the pop-up menu):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const nHours As Long = 6
Dim dTimeAdjust As Double
With Target
If .Cells.Count 1 Then Exit Sub
If .Address(False, False) = "A4" Then
If Not IsEmpty(.Value) Then
On Error Resume Next
dTimeAdjust = nHours / 24
Application.EnableEvents = False
.Value = .Value - dTimeAdjust - _
(.Value <= dTimeAdjust)
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End With
End Sub


In article ,
Megs wrote:

If I key in the time "9:00:00 AM" in cell A4 and press the enter key, I
wanted cell A4 to display "3:00:00 AM". If this is possible, please tell me
the detailed procedure.

For your information, "9:00:00 AM" is the U.S. time, once I entered the
time excel in cell A4 for example, it should automatically become "3:00:00
AM" in German time in the SAME A4 cell.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Automatic time conversion in the SAME cell

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A4" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If IsNumeric(.Value) Then
If .Value < 1 Then
If .Value = TimeSerial(6, 0, 0) Then
.Value = .Value - TimeSerial(6, 0, 0)
Else
.Value = .Value + 1 - TimeSerial(6, 0, 0)
End If
End If
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Megs" wrote in message
...
Hi,

If I key in the time "9:00:00 AM" in cell A4 and press the enter key, I
wanted cell A4 to display "3:00:00 AM". If this is possible, please tell

me
the detailed procedure.

For your information, "9:00:00 AM" is the U.S. time, once I entered the
time excel in cell A4 for example, it should automatically become "3:00:00
AM" in German time in the SAME A4 cell.

Thanks in advance.

Regards,
Megs



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default Automatic time conversion in the SAME cell

Thank you Bob, it works for a single cell, but what if I wanted to specify a
range of cell? Like the following:
1. The entire workbook or
2. A4 to C22?

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A4" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If IsNumeric(.Value) Then
If .Value < 1 Then
If .Value = TimeSerial(6, 0, 0) Then
.Value = .Value - TimeSerial(6, 0, 0)
Else
.Value = .Value + 1 - TimeSerial(6, 0, 0)
End If
End If
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Megs" wrote in message
...
Hi,

If I key in the time "9:00:00 AM" in cell A4 and press the enter key, I
wanted cell A4 to display "3:00:00 AM". If this is possible, please tell

me
the detailed procedure.

For your information, "9:00:00 AM" is the U.S. time, once I entered the
time excel in cell A4 for example, it should automatically become "3:00:00
AM" in German time in the SAME A4 cell.

Thanks in advance.

Regards,
Megs




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default Automatic time conversion in the SAME cell

Thank you JE, it works for a single cell, but what if I wanted to specify a
range of cell? Like the following:
1. The entire workbook or
2. A4 to C22?


"JE McGimpsey" wrote:

One way:

Put this in your worksheet code module (right-click the worksheet tab
and choose View Code from the pop-up menu):

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const nHours As Long = 6
Dim dTimeAdjust As Double
With Target
If .Cells.Count 1 Then Exit Sub
If .Address(False, False) = "A4" Then
If Not IsEmpty(.Value) Then
On Error Resume Next
dTimeAdjust = nHours / 24
Application.EnableEvents = False
.Value = .Value - dTimeAdjust - _
(.Value <= dTimeAdjust)
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End With
End Sub


In article ,
Megs wrote:

If I key in the time "9:00:00 AM" in cell A4 and press the enter key, I
wanted cell A4 to display "3:00:00 AM". If this is possible, please tell me
the detailed procedure.

For your information, "9:00:00 AM" is the U.S. time, once I entered the
time excel in cell A4 for example, it should automatically become "3:00:00
AM" in German time in the SAME A4 cell.




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Automatic time conversion in the SAME cell

It works as the data is entered, so just change the A4 constant to A4:C22

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Megs" wrote in message
...
Thank you Bob, it works for a single cell, but what if I wanted to specify

a
range of cell? Like the following:
1. The entire workbook or
2. A4 to C22?

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A4" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If IsNumeric(.Value) Then
If .Value < 1 Then
If .Value = TimeSerial(6, 0, 0) Then
.Value = .Value - TimeSerial(6, 0, 0)
Else
.Value = .Value + 1 - TimeSerial(6, 0, 0)
End If
End If
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Megs" wrote in message
...
Hi,

If I key in the time "9:00:00 AM" in cell A4 and press the enter

key, I
wanted cell A4 to display "3:00:00 AM". If this is possible, please

tell
me
the detailed procedure.

For your information, "9:00:00 AM" is the U.S. time, once I entered

the
time excel in cell A4 for example, it should automatically become

"3:00:00
AM" in German time in the SAME A4 cell.

Thanks in advance.

Regards,
Megs






  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Automatic time conversion in the SAME cell

but what if I wanted to specify a range of cell?

Then you probably should have specified that in your problem statement,
in which you wrote about a single cell.

Any other rocks to bring?

This modification will work for A4:C22:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const nHours As Long = 6
Dim dTimeAdjust As Double
With Target
If .Cells.Count 1 Then Exit Sub
If Not Intersect(.Cells, Me.Range("A4:C22")) Is Nothing Then
If Not IsEmpty(.Value) Then
On Error Resume Next
dTimeAdjust = nHours / 24
Application.EnableEvents = False
.Value = .Value - dTimeAdjust - _
(.Value <= dTimeAdjust)
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End With
End Sub



In article ,
Megs wrote:

Thank you JE, it works for a single cell, but what if I wanted to specify a
range of cell? Like the following:
1. The entire workbook or
2. A4 to C22?

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default Automatic time conversion in the SAME cell

No more rocks, thanks JE. Problem solved. :)

"JE McGimpsey" wrote:

but what if I wanted to specify a range of cell?


Then you probably should have specified that in your problem statement,
in which you wrote about a single cell.

Any other rocks to bring?

This modification will work for A4:C22:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const nHours As Long = 6
Dim dTimeAdjust As Double
With Target
If .Cells.Count 1 Then Exit Sub
If Not Intersect(.Cells, Me.Range("A4:C22")) Is Nothing Then
If Not IsEmpty(.Value) Then
On Error Resume Next
dTimeAdjust = nHours / 24
Application.EnableEvents = False
.Value = .Value - dTimeAdjust - _
(.Value <= dTimeAdjust)
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End With
End Sub



In article ,
Megs wrote:

Thank you JE, it works for a single cell, but what if I wanted to specify a
range of cell? Like the following:
1. The entire workbook or
2. A4 to C22?


  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default Automatic time conversion in the SAME cell

Thanks Bob. Problem solved. :)

"Bob Phillips" wrote:

It works as the data is entered, so just change the A4 constant to A4:C22

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Megs" wrote in message
...
Thank you Bob, it works for a single cell, but what if I wanted to specify

a
range of cell? Like the following:
1. The entire workbook or
2. A4 to C22?

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A4" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If IsNumeric(.Value) Then
If .Value < 1 Then
If .Value = TimeSerial(6, 0, 0) Then
.Value = .Value - TimeSerial(6, 0, 0)
Else
.Value = .Value + 1 - TimeSerial(6, 0, 0)
End If
End If
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Megs" wrote in message
...
Hi,

If I key in the time "9:00:00 AM" in cell A4 and press the enter

key, I
wanted cell A4 to display "3:00:00 AM". If this is possible, please

tell
me
the detailed procedure.

For your information, "9:00:00 AM" is the U.S. time, once I entered

the
time excel in cell A4 for example, it should automatically become

"3:00:00
AM" in German time in the SAME A4 cell.

Thanks in advance.

Regards,
Megs






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
Cell References [email protected] Excel Discussion (Misc queries) 2 November 15th 06 11:37 PM
Using an offset formula for the reference in a relative reference Cuda Excel Worksheet Functions 6 November 15th 06 05:12 PM
Help with this conditional IF statement C-Dawg Excel Discussion (Misc queries) 3 May 15th 06 06:01 PM
multiplycation of money cell and time cell engr625 Excel Worksheet Functions 1 August 3rd 05 04:53 AM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM


All times are GMT +1. The time now is 06:49 AM.

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"