Anyone can help me for vba?

jovie

Board Regular
Joined
Nov 13, 2015
Messages
68
Private Sub Worksheet_Change(ByVal Target As Range)

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(, 15).Value = Date

n = Range("g65535").End(xlUp).Row
For i = 8 To n
If Not (Intersect(Target, Range("G" & i)) Is Nothing) Then
Range("J" & i).Value = Range("J" & i).Value + Range("G" & i).Value
End If
If Not (Intersect(Target, Range("H" & i)) Is Nothing) Then
Range("J" & i).Value = Range("J" & i).Value - Range("H" & i).Value
End If
Next

n = Range("r65535").End(xlUp).Row
For i = 8 To n

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("S" & i)) Is Nothing) Then
Range("T" & i).Value = Range("T" & i).Value - Range("S" & i).Value
End If
Next
End Sub

I wrote this code, however after apply the code, only the update date function and the code below is working, the others function all cant work
If Not (Intersect(Target, Range("H" & i)) Is Nothing) Then
Range("J" & i).Value = Range("J" & i).Value - Range("H" & i).Value
End If
Next
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try changing:

Code:
If Not (Intersect(Target, Range("H" & i)) Is Nothing) Then

to

Code:
If Not Intersect(Target, Range("H" & i)) Is Nothing Then
 
Upvote 0
Try changing:

Code:
If Not (Intersect(Target, Range("H" & i)) Is Nothing) Then

to

Code:
If Not Intersect(Target, Range("H" & i)) Is Nothing Then

still the same.....
just I set 5 function for the code, but it only work 2 function
 
Upvote 0
You should probably set Application.enableevents to False at the beginning and return it to True at the end of the routine as data written within the sub will trigger another worksheet_change event.
 
Upvote 0
You should probably set Application.enableevents to False at the beginning and return it to True at the end of the routine as data written within the sub will trigger another worksheet_change event.

It is solved!!! Thanks you
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
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