+ Reply to Thread
Results 1 to 5 of 5

Need VBA to copy data from looped sheets into summary sheet

  1. #1
    Registered User
    Join Date
    03-21-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2003 and 2010
    Posts
    16

    Need VBA to copy data from looped sheets into summary sheet

    Hey Guys,

    I'm not too familiar with loop commands, and not even sure if looping worksheets to get data and pasting them into the summary is the best way for what i want to achieve.

    I have a workbook with several sheets, the number of sheets will be different depending on the source.. However, the layout will be consistent (ie red Combined sheet in the middle somewhere, followed by the summary)

    I need a macro which can extract certain information from selected cells from the various sheets to the right of the summary sheet, and paste them into the appropriate cells in the summary sheet in a descending order (ie, not writing over the previous entry)

    I've attached a sample for reference. testhelp.zip

    Basically, the summary sheet should be populated with the corresponding data in the sheets that follow it (blue tabs).
    The first entry has been entered manually into the summary tab as an example.

    if anyone can help me write a macro that can loop through the sheets and fetch the info into the summary sheet, that would be absolutely fantastic!

    Cheers,
    Caleb

  2. #2
    Registered User
    Join Date
    03-21-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2003 and 2010
    Posts
    16

    Re: Need VBA to copy data from looped sheets into summary sheet

    Hi everyone,

    Can someone help me with a loop command to be used within the following macro at all?
    I've written this macro, and it does what i need it to do; however I still need to manually select the "OU" so the macro can finish.

    At the moment, The macro asks for which OU to generate the report for. The OU is displayed only in column "CF".. The length of this column can range from 2 values through to about 100, starting at cell CF2, going down.

    I believe there is a way to loop the following, which would cycle through the list, without having to enter each and every OU value, which is what is required at the moment - takes forever! I am somewhat clueless about how to use the loop function properly, and have tried several times but not making much headway.

    Please Login or Register  to view this content.
    I would imagine a range would need to be declared, and then a loop to cycle through the list. I also don't know how to put in an appropriate error handler, which will exit out of the macro when something goes wrong.. At the moment, I can't stop the macro from running when I accidentally enter the wrong OU.. however with a working automated loop that can cycle through the OUs, this probably wont even be required.

    Any assistance on this would be much appreciated... I still have about 90 sheets of raw data to go through, each with varying numbers of OUs needing to be filtered and summarized. I'm thinking days of entering OUs.. !!

    On a side note, the macro is taking long to run, even after i turned off the screen updates. I suspect that it is due to the macro calculating the the entire column whenever the red codes are used. This is needed as the raw data can extend to varying lengths, and this is used to make sure no data is missed in the calculations. is there another way for writing a formula functions that can determine where the last data cell is within the column in order to be used in the calculation, ie not have to total the whole column every single time?

    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Need VBA to copy data from looped sheets into summary sheet

    OK. Obvioulsy you are taking a crash course in vba and there is no shame in that. I think we will be able to help you with a little guidance from you on what you want. Let's start with the basics:

    1) You almost never need to use .select or .activate to use an object. So things like:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    are the same but the first is faster.

    2) You almost always want to turn off some of excel functionalities that will slow down your code:

    Please Login or Register  to view this content.
    ...code goes here

    Please Login or Register  to view this content.
    3) If you only want the results of a forumla rather than the formula itself then you can calculate it in memory and then leave only the value

    Please Login or Register  to view this content.
    will leave only the values while:
    Please Login or Register  to view this content.
    will leave the whole formula.

    I have to go now but post back and we can work on improving your code further.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Registered User
    Join Date
    03-21-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2003 and 2010
    Posts
    16

    Re: Need VBA to copy data from looped sheets into summary sheet

    Quote Originally Posted by abousetta View Post
    OK. Obvioulsy you are taking a crash course in vba and there is no shame in that. I think we will be able to help you with a little guidance from you on what you want. Let's start with the basics:

    .....

    I have to go now but post back and we can work on improving your code further.

    abousetta
    Awesome !!
    Appreciate any advice, tips and guidance you can offer. Please keep em coming!
    Simple shortcuts to make the codes tidier and faster are always a good thing!

    Thanks!

  5. #5
    Registered User
    Join Date
    03-21-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2003 and 2010
    Posts
    16

    Unhappy Re: Need VBA to copy data from looped sheets into summary sheet

    Hey guys,

    I'm still having trouble with looping through a column of unique values.
    At the moment, I have determined the unique values in all my data into a separate column, where I can then bring up an input box that allows me to filter all my data based on the required OU for my report.

    Basically, I need to filter the data to show only information relevant to the OU, then either export it to a new sheet, or calculate, copy and paste the totals to a new sheet.

    The current code works (as per previous post); however I still need to rely upon manually entering the OU (which I had another macro find and show by extracting the unique values - The other macro was designed to filter the state and BU).

    I need a loop in place to automate the filtering, removing the need to manually enter an OU altogether. Is there a way this can be achieved?


    How do I replace this...

    Please Login or Register  to view this content.
    with a loop function that will filter field 15 with all the OUs listed in column CF.. Essentially, I want excel to perform the task of running my entire code for all the OUs that are listed in a column, rather than having to manually enter each OU to generate the report.

    Anyone? Solving this issue will literally save me hours of repeatedly entering OUs into an input box.

+ 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