View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Vince Vince is offline
external usenet poster
 
Posts: 102
Default Formula to derive "Year-To_Date"

I tried it on one cell and worked fine, thanks. I do need to however
continue this fomat all the way down the page for about 15 rows, since I have
different numbers in the cells that I need to get the Year-To-Date for. How
would I modify this Macro so that it applies to more than one cell. Thanks

"Gary''s Student" wrote:

Try this small worksheet event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim D2 As Range, B2 As Range
Set B2 = Range("B2")
Set t = Target
Set D2 = Range("D2")
If Intersect(B2, t) Is Nothing Then Exit Sub
Application.EnableEvents = False
D2.Value = D2.Value + B2.Value
B2.Clear
Application.EnableEvents = True
End Sub


Because it is worksheet code, it is very easy to install and automatic to use:

1. right-click the tab name near the bottom of the Excel window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm
--
Gary''s Student - gsnu200817


"Vince" wrote:

I have a column designated as "Year-To-Date", and like to enter a formula so
that every time I enter a value in a cell in the same row (for instance B2),
it can then add that value to the current value in the Year-To-Date cell (for
instance D2) and give me a total Year-To_Date?? Any help appreciated.