Solved

Excel Add to a cell

Posted on 2012-12-28
7
157 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

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…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

821 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