Decrement from a total

Brad L

New Member
Joined
Feb 5, 2009
Messages
34
Hi,
I'm using the following code to decrement expenses (column C) from a total (A1).

This works great with one small problem. If I change any value in column C, say from $100 to $50, it deducts both values from A1 instead of updating the value.

Example:
A1 is $500

C5 is changed from $100 to $50. A1 should read $450, instead it's deducting both and reading $350 even though I replaced the original value.

thx

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C3:C20")) Is Nothing Then
Application.EnableEvents = False
If Target.Value = "" Then
Application.Undo
Range("A1").Value = Range("A1").Value + Target.Value
Target.ClearContents
Else
Range("A1").Value = Range("A1").Value - Target.Value
End If
Application.EnableEvents = True
End If
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I was not able to reproduce the problem with the code you posted, I got the values you expected.

Set a break point in the code to see when it called then step through it with F8 and check the values.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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