LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 102
Default Formula to derive "Year-To_Date"

Hi,

I'm almost there, just need a few small modifications:
1. YTD Column is E and starts from E2 (My error, sorry) and the data will
still come from Column B (starting from B2 and down).
2. Since I make a new Monthly Statement every month, I have a template that
fill up and resave for every month. Therefore the next month I re-open the
template and fill up column B with new values BUT column E (Year-To-Date)
needs to keep the previous month's value/data and get updated automatically
with the current month's value (COLUMN B cells) added to the total figure in
the specific cell (COLUMN E cells). ANY HELP TO MAKE THIS FUNCTIONAL IS
GREATLY APPRECIATED.



"Gary''s Student" wrote:

Hi Vince:

Here is a new version. It must replace the old version.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim B As Range
Set B = Range("B1:B100")
Set t = Target
If Intersect(B, t) Is Nothing Then Exit Sub
Application.EnableEvents = False
With t.Offset(0, 1)
.Value = .Value + t.Value
t.Clear
End With
Application.EnableEvents = True
End Sub

You must also pdate the statement:

Set B = Range("B1:B100")

to suite your needs.

--
Gary''s Student - gsnu200817


"Vince" wrote:

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.



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
Working out age from "Day" "Month" "Year" timmyc Excel Worksheet Functions 4 February 5th 06 03:07 PM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"