+ Reply to Thread
Results 1 to 7 of 7

Add to Total and Clear Macro

  1. #1
    Registered User
    Join Date
    08-22-2008
    Location
    USA
    Posts
    10

    Add to Total and Clear Macro

    Hi all.

    I'm relatively new to Excel and especially to macros. The spreadsheet I'm working on deals with inventory levels, and I want to write a macro to connect two worksheets. The first sheet is updated weekly with new purchases, and the first sheet is supposed to be a cumulative total of inventory. So, I am trying to write a macro that would add the quantity on sheet one to the quantity on sheet two, and then clear sheet one. This will be done every week to keep a running tally of inventory. Any idea how this could be done?

    Thank you for any help, and I'm sorry if a similar question has already been asked.

  2. #2
    Forum Contributor wmorrison49's Avatar
    Join Date
    09-25-2007
    Posts
    267
    Hi abcd12,
    If your quantity on Sheet1 is in A1 and you want your running total to be in A1 of Sheet2, try this code. You can put in in the ThisWorkbook section of VB editor.

    Dim Count As Long

    Sheets("Sheet1").Activate
    Count = Range("A1")
    Sheets("Sheet2").Activate
    Range("A1") = Range("A1") + Count
    Sheets("Sheet1").Activate
    Range("A1").ClearContents

  3. #3
    Registered User
    Join Date
    08-22-2008
    Location
    USA
    Posts
    10
    Thank you very much for your help. How can I apply this macro to the entire sheet?

  4. #4
    Forum Contributor wmorrison49's Avatar
    Join Date
    09-25-2007
    Posts
    267
    Do you mean have every cell from Sheet2 do a running total from the corresponding cell in Sheet1 and then clear Sheet1?

  5. #5
    Registered User
    Join Date
    08-22-2008
    Location
    USA
    Posts
    10
    Quote Originally Posted by wmorrison49 View Post
    Do you mean have every cell from Sheet2 do a running total from the corresponding cell in Sheet1 and then clear Sheet1?
    Yes that what I mean, if it's possible.

    And thanks for your help, wmorrison

  6. #6
    Forum Contributor wmorrison49's Avatar
    Join Date
    09-25-2007
    Posts
    267
    Well, it's not beautiful code, but it works. You'll need to have your new data in Sheet1, your previous running total in Sheet2, and then your up to date running total will be in Sheet3. Here's the code:

    Sheets("Sheet3").Activate
    Range("A1").Select
    ActiveCell = "=Sheet1!A1+Sheet2!A1"
    Selection.AutoFill Destination:=Range("A1:A1000"), Type:=xlFillDefault
    Range("A1:A1000").Select
    Selection.AutoFill Destination:=Range("A1:AZ1000"), Type:=xlFillDefault
    Range("A1:AZ1000").Select

    Range("A1:AZ1000").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

  7. #7
    Registered User
    Join Date
    08-22-2008
    Location
    USA
    Posts
    10
    hmmm...that gives me a Run Time 4001 Error, can't seem to figure out what's wrong

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to splitt texts into words? (collecting word and compounds)
    By wali in forum Excel Programming / VBA / Macros
    Replies: 53
    Last Post: 02-03-2008, 04:06 AM
  2. Macro to submit expenditure total and then move down a row
    By Zyphon in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-31-2008, 06:20 AM
  3. Bubble Chart Macro (AttachLabelsToPoints)
    By dbrunner281 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2007, 11:04 AM
  4. macro to work for variable number of rows
    By incognito in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-18-2007, 08:48 PM
  5. Macro for Clear contents
    By nandhamnk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2006, 12:20 AM

Bookmarks

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