# Calculating a running total

1. ## Calculating a running total

Hi guys.

I figure this has got to be a popular question. I want to calculate a running total (so add a new value to its original value). For example, cell A1 is the one I will be changing daily, and cell B2 is the one that I want a running total in. So if I start with A1 being 5, B2 should be 5. If the next day I type in 3 into A1, B2 should now read 8. However I want to do this for a column length, not just cells A1 & B1. So column B would be the running total of the column A values. If A2 is 3 one day and the next it is 6, B2 should on the second day read 9. And on and on down the columns.

I tried doing this without VBA using iterations, but that didn't work. Every time I did that it would add values going down, which was weird cuz none of the cells referenced the cell above it. I think I'm forced to use VBA on this one, and I don't know how to use it. Could anyone tell me exactly what I need to type into a VBA module in order to perform this? I looked it up online and there were solutions out there but I didn't know if they would work since I have multiple sheets in this file. (I'm only calculating the running total in one sheet, the others aren't doing anything special.) I need all the sheets in my file and I didn't know if VBA modules are sheet specific/ if you need to be sheet specific when coding. If anyone wants me to attach the file, I can.

Another question I have (since I know nothing about VBA) is how do modules work? Do you need to turn them on in the Excel spreadsheet itself? Or when you save it does it just automatically apply itself to the file its attached to?

On another note, if anyone can tell me how to do this WITHOUT VBA, that would be like 100x more fantastic.

2. ## Re: Calculating a running total

There is a very easy way to do this via VBA. Put this in the sheet that you are wanting to do this on:

``Please Login or Register  to view this content.``

3. ## Re: Calculating a running total

What do I type into the worksheet itself? In other words, how do I call the function in the excel workbook?

4. ## Re: Calculating a running total

Hello,

You put the code into the worksheet change Event and everytime you change the value in A1 the Change Event takes care of the rest.

5. ## Re: Calculating a running total

Correct. Access the Visual Basic Editor. Double click the sheet you want the code to operate on, copy and paste the code in the code window. Go back to your spreadsheet and on the sheet you opted to run the code on, type a number into any row in column A. The code will automatically input add it to the value in column B of the same row.

6. ## Re: Calculating a running total

Ok. Its still not working for me. Here is what I have. I want column D to be my running total column. Column C is the daily column from which column D should be taking from. I changed the range part of the code to reference column C. Maybe I need to specify the worksheet? If you guys can get this to work that would be SO awesome. workhours.xlsm

7. ## Re: Calculating a running total

You put the correct code in the wrong spot (under module 2) and in the correct spot (sheet1 Daily) you had incorrect code. Removal all the code in the sheet1 Daily procedure and replace with the code you have under module 2. When I did this it worked just fine for me.

Note: Since it is a worksheet change event you do not need to specify a worksheet.

8. ## Re: Calculating a running total

OMG IT WORKS (after I took up your edits, stnkynts). Today is a really good day.

Thanks stnkynts!

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1