Private Sub Worksheet_Change(ByVal Target As Range)
n = Range("g65535").End(xlUp).Row
For i = 8 To n
'Auto using formula to change the value of Total tools out per week'
If Not Intersect(Target, Range("G" & i)) Is Nothing Then
Range("U" & i).Value = Range("U" & i).Value + Range("G" & i).Value
End If
If Not Intersect(Target, Range("H" & i)) Is Nothing Then
Range("U" & i).Value = Range("U" & i).Value + Range("H" & i).Value
End If
'Auto using formula to change the value of moving stock balance'
If Not Intersect(Target, Range("G" & i)) Is Nothing Then
Range("I" & i).Value = Range("G" & i).Value + Range("I" & i).Value
End If
If Not Intersect(Target, Range("H" & i)) Is Nothing Then
Range("I" & i).Value = Range("I" & i).Value - Range("H" & i).Value
End If
'Auto using formula to change the value of main stock balance'
If Not Intersect(Target, Range("R" & i)) Is Nothing Then
Range("T" & i).Value = Range("T" & i).Value + Range("R" & i).Value
End If
If Not Intersect(Target, Range("G" & i)) Is Nothing Then
Range("T" & i).Value = Range("T" & i).Value - Range("G" & i).Value
End If
Next
'When the storage are low, show the warning message and highlight the tools.'
u = Cells(Target.Row, "U")
v = Cells(Target.Row, "V")
If Target.Row > 7 And Target.Column = 8 Then
If (u > 5 And v <= 8) Or (u < 5 And v <= 4) And Range("item").Interior.ColorIndex <> 3 Then
MsgBox "Storage is Low !!" & vbNewLine & "Please proceed to Order.", vbOKOnly, "Warning"
Range("C" & Target.Row, "K" & Target.Row).Interior.ColorIndex = 3
Range("N" & Target.Row, "W" & Target.Row).Interior.ColorIndex = 3
Range("W" & Target.Row).Value = "Low"
Else: Range("W" & Target.Row).Value = "Sufficient"
End If
End If
If Target.Row > 7 And Target.Column = 18 Then
If (u > 5 And v > 8) Or (u < 5 And v > 4) Then
Range("C" & Target.Row, "K" & Target.Row).Interior.ColorIndex = 0
Range("N" & Target.Row, "W" & Target.Row).Interior.ColorIndex = 0
Range("W" & Target.Row).Value = "Sufficient"
End If
End If
'Auto change the date when there is tools being taken out.'
Dim rng As Range
Set rng = Target.Parent.Range("Moving_Stock_out")
If Target.count > 1 Then Exit Sub
If Intersect(Target, rng) Is Nothing Then Exit Sub
Target.Offset(, 16).Value = Date
End Sub
I have write this code, however , there is two serious problem
One is about
I want to change U's value once I change G's Value or H's valueIf Not Intersect(Target, Range("G" & i)) Is Nothing Then
Range("U" & i).Value = Range("U" & i).Value + Range("G" & i).Value
End If
If Not Intersect(Target, Range("H" & i)) Is Nothing Then
Range("U" & i).Value = Range("U" & i).Value + Range("H" & i).Value
End If
However, first time to key in in G or H will result weird value in U
Like The U is zero, and I enter 1 into G, and U will become 2
something like this.
Another one is
This one is only will being toggle inu = Cells(Target.Row, "U")
v = Cells(Target.Row, "V")
If Target.Row > 7 And Target.Column = 8 Then
If (u > 5 And v <= 8) Or (u < 5 And v <= 4) And Range("item").Interior.ColorIndex <> 3 Then
MsgBox "Storage is Low !!" & vbNewLine & "Please proceed to Order.", vbOKOnly, "Warning"
Range("C" & Target.Row, "K" & Target.Row).Interior.ColorIndex = 3
Range("N" & Target.Row, "W" & Target.Row).Interior.ColorIndex = 3
Range("W" & Target.Row).Value = "Low"
Else: Range("W" & Target.Row).Value = "Sufficient"
End If
End If
If Target.Row > 7 And Target.Column = 18 Then
If (u > 5 And v > 8) Or (u < 5 And v > 4) Then
Range("C" & Target.Row, "K" & Target.Row).Interior.ColorIndex = 0
Range("N" & Target.Row, "W" & Target.Row).Interior.ColorIndex = 0
Range("W" & Target.Row).Value = "Sufficient"
End If
End If
,if the storage is low, it wont be turn red or write low in column W, it will write sufficient in column WElse: Range("W" & Target.Row).Value = "Sufficient"
End If