ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Change :47:57 to 0:47:57 (https://www.excelbanter.com/excel-worksheet-functions/150500-change-47-57-0-47-57-a.html)

jeannie v

Change :47:57 to 0:47:57
 
Hi Experts:

I have a Macro that will pop time to a worksheet...the problem is I can't
determine how to make it pop with a left Zero fill if there are no hours.
Example: :47:57 change to 0:47:57 whe the Macro pops instead of the :47:57.

Can anyone tell me how to do this?

Thanks for your assistance,
--
jeannie v

Bob Phillips

Change :47:57 to 0:47:57
 
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== 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 Left(.Value, 1) = ":" Then
.Value = "0" & .Value
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

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"jeannie v" wrote in message
...
Hi Experts:

I have a Macro that will pop time to a worksheet...the problem is I can't
determine how to make it pop with a left Zero fill if there are no hours.
Example: :47:57 change to 0:47:57 whe the Macro pops instead of the
:47:57.

Can anyone tell me how to do this?

Thanks for your assistance,
--
jeannie v




jeannie v

Change :47:57 to 0:47:57
 
Good Morning, Bob:

Excellent! It worked perfectly!!!! Thank you for lending your expertise!
--
jeannie v


"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== 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 Left(.Value, 1) = ":" Then
.Value = "0" & .Value
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

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"jeannie v" wrote in message
...
Hi Experts:

I have a Macro that will pop time to a worksheet...the problem is I can't
determine how to make it pop with a left Zero fill if there are no hours.
Example: :47:57 change to 0:47:57 whe the Macro pops instead of the
:47:57.

Can anyone tell me how to do this?

Thanks for your assistance,
--
jeannie v






All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com