Nelson78
Well-known Member
- Joined
- Sep 11, 2017
- Messages
- 526
- Office Version
- 2007
Hello everybody.
I've in sheet1 a Change Event in case a cell value is changed.
It seems to work well, except if I insert 0 in a cell. I mean: if I find that cell with 20 and change it with zero, nothing happens. If I insert, for instance, 0,0000000001 the change event works regularly.
The red instruction is the questioned one.
Thank's.
I've in sheet1 a Change Event in case a cell value is changed.
It seems to work well, except if I insert 0 in a cell. I mean: if I find that cell with 20 and change it with zero, nothing happens. If I insert, for instance, 0,0000000001 the change event works regularly.
The red instruction is the questioned one.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
Dim lr As Long, lc As Long
Dim rng As Range
lr = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
lc = Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
If lr < 3 Or lc < 4 Then Exit Sub
On Error GoTo Skip
If Target.Column > 3 And Target.Row > 2 Then
If Cells(Target.Row, 2) = "H" Then
Application.EnableEvents = False
Set rng = Range(Cells(Target.Row, 4), Cells(Target.Row, lc))
Debug.Print rng.Address
fr = Target.Row
fc = Target.Column
Cells(fr + 1, fc).Value = Cells(fr - 1, fc).Value / Cells(fr, fc).Value
Cells(fr + 1, fc).NumberFormat = "0.00"
[COLOR="#FF0000"][B]Cells(fr, 3).Value = Application.Sum(rng)[/B][/COLOR]
Cells(fr + 1, 3).Value = Cells(fr - 1, 3).Value / Cells(fr, 3).Value
Cells(fr + 1, 3).NumberFormat = "0.00"
Dim varResult As Variant
varResult = Application.WorksheetFunction.SumIf( _
Arg1:=Range(Cells(433, 2), Cells(501, 2)), _
Arg2:="H", _
Arg3:=Range(Cells(433, fc), Cells(501, fc)))
Cells(503, fc).Value = varResult
Cells(504, fc).Value = Cells(502, fc).Value / Cells(503, fc).Value
Cells(503, 3).Value = _
Application.Sum(Range(Cells(503, 4), Cells(503, lc)))
Cells(504, 3).Value = Cells(502, 3).Value / Cells(503, 3).Value
End If
End If
Skip:
Application.EnableEvents = True
End Sub
Thank's.