+ Reply to Thread
Results 1 to 12 of 12

Repeated action - shorten macro - copy from each sheet to summary sheet

  1. #1
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Repeated action - shorten macro - copy from each sheet to summary sheet

    Hello,

    I have this macro which I have generated and edited with the recorder.


    Please Login or Register  to view this content.
    This macro copies a range from the first sheet of the workbook and pastes it in the sheet named "Summary" in C4
    then copies the same range from the second sheet of the workbook and pastes it in the sheet named "Summary" in C7
    and so on...I would like to begin the copy/paste action, starting from the first worksheet and continuing in the order the worksheets are in the workbook. This is the reason I edited the above macro as above.

    Is it possible to shorten the macro and to do the above for all the sheets found in a workbook, starting from sheet1 and continuing to the last sheet of the workbook, but disregard sheets named, Summary2 and summary3?

    Thank you

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    Where should data from the other sheets be copied to in the Summary Sheet? To column D, then E, etc?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    Hi arlu201,

    thanks for your reply. Yes all the data from the other sheets should be copied into the summary sheet. starting from c4, then c7,then c10, then c13 and so on.

    So

    range W1785:ag1786 in worksheet(1) should be copied in summary sheet in C4
    range W1785:ag1786 in worksheet(2) should be copied in summary sheet in C7
    range W1785:ag1786 in worksheet(3) should be copied in summary sheet in C10
    range W1785:ag1786 in worksheet(4) should be copied in summary sheet in C13
    range W1785:ag1786 in worksheet(5) should be copied in summary sheet in C16

    and so on.

    Thank you

  4. #4
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    I found the macro by RDB, CopyRangeFromMultiWorksheets here

    http://www.rondebruin.nl/copy2.htm

    Please Login or Register  to view this content.
    I have manage to edit it to achieve what I was looking above.

    I am encountering a small issue though. When I am trying to consolidate a second range, AU1785:BE1786 to the Summary worksheet, the consolidated range AU1785:BE1786 in the summary worksheet is pasted below the consolidated W1785:ag1786. Is it possible to have them pasted at the same starting row? I can provide an example, if the above is not making much sense.

    Thank you

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    Try this code -
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  6. #6
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    Hi arlu1201,

    The macro works great! One small issue, the values that are copied contain formulas, so when they are copied to the summary sheet they return a #REF error.
    Is it possible to copy only the values and source formatting?
    Thank you for your help!

  7. #7
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    To my surprise I managed to edit the code successfully,

    Please Login or Register  to view this content.

    Thank you for your help and the simple yet effective macro!

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    Change this line from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    Np, glad you got it working.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  10. #10
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    When I try to paste a different range in column O

    Please Login or Register  to view this content.
    for some reason the paste special does not work, the values are copied in a different font/formatting. Trying to figure this out and I'm sure its something obvious but don't know what.

    Thank you

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    Yes...the pastevaluesandnumberformats is only for the numbers. Change your code from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor sans's Avatar
    Join Date
    10-19-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    550

    Re: Repeated action - shorten macro - copy from each sheet to summary sheet

    That did it, everything works great! Many many thanks for the help Arlette! Thread solved

+ 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