Urgent!!!! Anyone can help me??

jovie

Board Regular
Joined
Nov 13, 2015
Messages
68
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
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
I want to change U's value once I change G's Value or H's value
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
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
This one is only will being toggle in
Else: Range("W" & Target.Row).Value = "Sufficient"
End If
,if the storage is low, it wont be turn red or write low in column W, it will write sufficient in column W
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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