+ Reply to Thread
Results 1 to 8 of 8

Macro to Total Volumes

  1. #1
    Forum Contributor
    Join Date
    06-16-2008
    Posts
    287

    Macro to Total Volumes

    Hi, i am looking to write a macro that will loop through a list of queues and then sum up the values for each queue from column S and AA from a different.

    I have attached a sample workbook that has 2 sheets. What i would like is for the macro to go through the list of queues on Column A in Volumes Sheet and then find these queues within the Source Sheet and if found sum up the values in Column S and AA and then put the value in Col D on Volumes Sheet, otherwise if the queue is not there then move onto the next cell.

    I am guessing I will have to write a for each loop but not sure where to start.

    Thanks in advance. Hope somebody can help.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to Total Volumes

    hi, it can be easily done by formula. Is macro obligatory?
    Attached Files Attached Files
    Last edited by watersev; 12-23-2010 at 06:33 AM.

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro to Total Volumes

    I can't work out what your aim is here.

    Does this workbook help?
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Forum Contributor
    Join Date
    06-16-2008
    Posts
    287

    Re: Macro to Total Volumes

    watersev and marcol, thanks for your help, the reason for the macro is that this needs to be ran every 2 hours and the source file gets changed so would need the formulas to be converted to values. I thought that i would be able to use a for each loop (i.e each queue that appears search for values in column s and aa and sum these up).

    thanks for your help guys.

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Macro to Total Volumes

    it may be loop code but why if you can use SUMIF function...

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro to Total Volumes

    Try this in a standard module
    Please Login or Register  to view this content.

    And in the sheet module Sheets("Volumes")
    Please Login or Register  to view this content.

    Click on "Update Sheet" in Sheets("Volumes") B2 to run the macro

    I have not put in any code to avoid over writing data entries already made as yet.

    Hope this helps
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    06-16-2008
    Posts
    287

    Re: Macro to Total Volumes

    Marcol, apologies for the delay in responding. I have tried running the sample file you have attached and i get a debug error at the following point:

    .Cells(4, ColNo).Select

    but when adding the code to my file this works fine, just wondering what the error is within the file you have attached. Also within your file you have attached a timestamp, would this mean for example if the time is over 10:00 then the data would be pasted within the correct column i.e. 10:00 is in Column E.

    Thanks for your help, really appreciated.

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Macro to Total Volumes

    ......and i get a debug error at the following point:

    .Cells(4, ColNo).Select
    My oversight, the code was designed to allow updating up to 1 hour after the required time, if say you need the values for 10:00, then you can get these figures any time between 10:00 and 10:59:59. when the time goes to 11:00 or over, you can't get another update until 12:00. This is where the error lies.

    Change the code to this
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    is now inside the if statement.

    The line is probably redundant as it is followed by another selected cell in the sheet change event.

    You can add to the sampling times if you need to but the code is only valid for whole hours e.g. 09:00, 10:00, etc.

    The "Time Stamp" is not automatic, it is updated by any change on the sheet, or by Formulas > Calculate Now. Do you need it to be automatic while the sheet is active?

    Does this clarify things for you?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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