auto divide option

F

Fernandez

Hi,

when i key in a cell with a number i want that to be divided by 40

Thanks

Fernandez
 
M

Mike H

Right click the sheet tab, view code and paste this in. Works on the range A1
- A100 so change to suit.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or Target.HasFormula Or IsEmpty(Target) Then
Exit Sub
If Not Intersect(Target, Range("A1:A100")) Is Nothing Then 'Change to suit
If IsNumeric(Target) Then
Application.EnableEvents = False
Target = Target / 40
Application.EnableEvents = True
On Error GoTo 0
End If
End If
End Sub

Mike
 
G

Gord Dibben

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Count > 1 Then Exit Sub
If Target.Address = "$B$5" Then
If Not IsNumeric(Target.Value) Then Exit Sub
Application.EnableEvents = False
With Target
.Value = .Value / 40
Application.EnableEvents = True

End With
End If
End Sub

Right-click on the sheet tab and "View Code"

Copy/paste the above into that module.

Adjust the $B$5 to suit. You did not give enough information to tailor a
specific cell or range of cells. For the entire sheet, just remove that line
and the End If line.

Alt + q to return to Excel.


Gord Dibben MS Excel MVP
 
Top