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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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
Back
Top