Word change to number automaticaly

dave2017

New Member
Joined
Jan 4, 2017
Messages
3
Hi Guys,

I am trying to make data in a cell change into a number !


For example if the following words

Off ,Holiday , Rotation or Travel

are typed or pasted into cell G4 it will automatically change to the following number 0:00

I hope you can help with this question.

Thanks Dave
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
try something like this!
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range




    ' The variable KeyCells contains the cells that will
    ' cause an alert when they are changed.
    Dim x As Long
    Dim y As Variant
    
    Set KeyCells = Range("G4")
    
    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing Then
            
            x = Target.Row
            y = Target.Value
            
            Application.EnableEvents = False
                If y = "Off" Or _
                        y = "Holiday" Or _
                        y = "Rotation" Or _
                        y = "Travel" Then
                            Target.Value = "0:00"
                            
                End If
            Application.EnableEvents = True
            
    End If
End Sub
 

dave2017

New Member
Joined
Jan 4, 2017
Messages
3
Hi Pedie,

Thanks for your reply, I am new to excel ! would it be possible for you to direct me on how to implement your theory.

Cheers Dave
 

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
from your vbe editor/project double click on your sheet name module (class) and place below code. this code should run every time value is changed in G4.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,193
Messages
5,594,767
Members
413,933
Latest member
Msar5586

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top