Hi omb3, good afternoon.
Please look at the code below, maybe it is what you need.
Sheet1 (Register) code :
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B4")) Is Nothing Then
MsgBox strValidationErrorMessage
On Error Resume Next
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
On Error GoTo 0
End If
If Not Intersect(Target, Range("G7")) Is Nothing Then
If AvoidEmptyCell() = 1 Then Exit Sub
Application.EnableEvents = False
Range("B4").Value = Target.Value
Application.EnableEvents = True
End If
End Sub
Sheet2 (Support) code :
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("M1")) Is Nothing Then
Application.EnableEvents = False
Sheets("Register").Range("B4").NumberFormat = """" & Target.Value & """" & "#0"
Application.EnableEvents = True
End If
End Sub
ThisWorkbook code :
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Index = Sheets("Register").Index Then
If Not Intersect(Target, Range("G7")) Is Nothing Then
With ActiveCell.Validation
.Delete
.Add Type:=xlValidateDecimal, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:=0, _
Formula2:=999999999
.ErrorMessage = strValidationErrorMessage
End With
Application.OnKey "~", "IncreaseValue"
Application.OnKey "+~", "DecreaseValue"
Else
Application.OnKey "~"
Application.OnKey "+~"
End If
Else
Application.OnKey "~"
Application.OnKey "+~"
End If
End Sub
Standard Module code :
Public Const strValidationErrorMessage = "Only number allowed !"
Function AvoidEmptyCell()
If IsEmpty(ActiveCell) Then
MsgBox strValidationErrorMessage
On Error Resume Next
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
On Error GoTo 0
AvoidEmptyCell = 1
Else
AvoidEmptyCell = 0
End If
End Function
Private Sub IncreaseValue()
If AvoidEmptyCell() = 1 Then Exit Sub
Application.EnableEvents = False
With Sheets("Register").Range("B4")
If IsNumeric(.Value) Then
If .Value < 0 Then
.Value = 0
Else
.Value = .Value + 1
End If
End If
End With
Application.EnableEvents = True
End Sub
Private Sub DecreaseValue()
If AvoidEmptyCell() = 1 Then Exit Sub
Application.EnableEvents = False
With Sheets("Register").Range("B4")
If IsNumeric(.Value) Then
If .Value <= 0 Then
.Value = 0
MsgBox "Cannot decrease anymore"
Else
.Value = .Value - 1
End If
End If
End With
Application.EnableEvents = True
End Sub
Sub FirstTimeSetValue()
Sheets("Register").Range("G7").Value = 2
End Sub
Regards
Bookmarks