Solved

Excel Add to a cell

Posted on 2012-12-28
7
155 Views
Last Modified: 2012-12-28
Cell A2 holds a value of $100.  Cell A1 is a cell used when an expense is made.  So, say we spent $10.  I want to enter $10 in cell A1 and have cell A2 automatially update to $110.  Or, i'd just like to be able to type over the $100 in cell A2 with $10 and have it know to add $100  + $10 to give me $110.
0
Comment
Question by:jnikodym
  • 4
  • 3
7 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38726998
If you do not change the locations described above then you can try this macro

Right-click on the sheet tab name
Select View code
Paste this code in the VBA window
Close the VBA window

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address Then [a2] = [a1] + [a2]
End Sub

Open in new window

0
 

Author Comment

by:jnikodym
ID: 38727039
That seemed to work.  Is there a way then to clear cell A1?
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38727058
Just select A1 and press the Del key or the Delete key
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jnikodym
ID: 38727066
I know that, but i was looking for a way for the code to do that.
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38727106
Try this....is this what you mean?
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address Then
Application.EnableEvents = False
[a2] = [a1] + [a2]
Range("A1").ClearContents
Application.EnableEvents = True
End If
End Sub

Open in new window

0
 

Author Comment

by:jnikodym
ID: 38727425
yes, but one more thing. Below is my code i'd like this code to work for the cells below as well.  For example, i'd like D11 = B11 + D11

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("B10").Address Then
Application.EnableEvents = False
[D10] = [B10] + [D10]
Range("B10").ClearContents
Application.EnableEvents = True
End If
End Sub
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 38727503
You should present all your requirements to start with instead of putting a new one every time you get a solution.

Try this...not tested

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.column =2 and target.row >9 Then
Application.EnableEvents = False
target.offset(0,2) = target + target.offset(0,2)
target.ClearContents
Application.EnableEvents = True
End If
End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now