Word change to number automaticaly

dave2017

New Member
Joined
Jan 4, 2017
Messages
13
Office Version
  1. 2019
Platform
  1. Windows
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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

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
13
Office Version
  1. 2019
Platform
  1. Windows
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,893
Messages
5,834,274
Members
430,273
Latest member
Windrunner

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