+ Reply to Thread
Results 1 to 6 of 6

Macro to extract subsections from selected sheets and paste them to another sheet

  1. #1
    Registered User
    Join Date
    02-26-2019
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    3

    Macro to extract subsections from selected sheets and paste them to another sheet

    Hi, I was wondering if the experts in here could help me out. I need to write a macro for what is essentially a data transfer task.

    I'm supposed to write a script to copy and paste data from individual sheets to a consolidated sheet (these are all in the same workbook). However, there are some conditions which have complicated this for me and I'm not sure how to move forward (please see the Excel file attached):

    (Point 1) I'm only supposed to transfer data from any sheet that contains the words "ABC Report" to the "Consolidated" sheet. The other sheets are supposed to be ignored by the script.
    (Point 2) Within each of the "ABC Report" sheets. I'm not supposed to transfer all the data. I'm only supposed to transfer data from specific Account IDs, in this case they would be "Account 1" and "Account 3".
    (Point 3) Within the specific account, I'm only supposed to copy certain cells into the "Consolidated" sheet. These cells are always in between "Currency" and "Total". For example, in the worksheet "ABC Report 1", I'm only supposed to copy cells A5:B6 into the "Consolidated" sheet. The data is always structured such that the cells are in between "Currency" and "Total", and there are always blank cells around "Currency" and "Total".
    (Point 4) After copying the data, the cells need to be separated and pasted into specific new columns in the "Consolidated" sheet. I have done an example for cells A5:B6 from "ABC Report 1":
    A5 from "ABC Report 1" has been pasted into G2 in "Consolidated",
    B5 from "ABC Report 1" has been pasted into K2 in "Consolidated",
    A6 from "ABC Report 1" has been pasted into G3 in "Consolidated",
    B6 from "ABC Report 1" has been pasted into K3 in "Consolidated",

    The template I have attached is a simplified version of my actual workbook which has thousands of rows and many tabs. I'm hoping that the simplified file presents the essence of the tasks that I need to accomplish. In particular, I need a macro that
    (i) Only looks at sheets that have the string "ABC Report" in the sheet name
    (ii) Only looks at specific account IDs. (for my actual report, I already have the list of these IDs and I'm thinking that I can create some sort of array for this?)
    (iii) For the specific account IDs, only copies the cells in between "Currency" and "Total" (I'm thinking that some sort of Offset from the account ID and CurrentRegion can be used, since there are always blank cells around the cells to be copied)
    (iv) Rearranges the cells when pasting them into "Consolidated".

    I'm hoping that once I have a basic general approach and macro I can adapt it to my actual sheet. I can't share the actual sheet because it contains sensitive data.

    In summary, I'm hoping my request is clear, and I would be eternally grateful to anyone who can help me out. Thank you.
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Macro to extract subsections from selected sheets and paste them to another sheet

    In your actual file, what is the name of the sheet that contains the list of IDs and in which range are they in?

    Cross-posted at: https://www.ozgrid.com/forum/forum/h...fic-conditions
    According to Forum rules, when you cross-post, please include a link to the thread in the other Forum.
    Last edited by Mumps1; 02-27-2019 at 03:04 PM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    02-26-2019
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    3

    Re: Macro to extract subsections from selected sheets and paste them to another sheet

    I have removed the cross post.

    I can't reveal the IDs, but i was hoping for some guidance on a general approach I can use, which i can then modify for myself for the actual workbook.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Macro to extract subsections from selected sheets and paste them to another sheet

    I don't need the actual ID's. Just the name of the sheet and the range that they are in.

  5. #5
    Registered User
    Join Date
    02-26-2019
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    3
    Quote Originally Posted by Mumps1 View Post
    I don't need the actual ID's. Just the name of the sheet and the range that they are in.
    The workbook has several sheets, the macro is only supposed to perform operations on several sheets that all have names starting with “046”. The range for each sheet is not fixed because each “046*” is a report that is pulled from a database weekly, depending on what entries were in the database this would vary weekly.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Macro to extract subsections from selected sheets and paste them to another sheet

    Since I really don't know how your actual data and sheets are organized, I based this macro on your description in your original thread. The macro works as you requested. Keep in mind that what works with a sample file will most often not work with the actual file. In order to get a working solution for your actual file, I would need to work with a copy of that file. You could post a copy here. The data, if confidential, can be de-sensitized. I wouldn't need all the data but just enough to make it representative of your actual data and how it is organized.
    Please Login or Register  to view this content.

+ 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. Replies: 3
    Last Post: 10-28-2014, 09:53 AM
  2. Replies: 2
    Last Post: 05-06-2014, 08:26 AM
  3. VBA macro to extract specific rows and paste them onto a new sheet
    By zicitron in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2013, 10:28 AM
  4. macro to cut & paste selected cells into new sheet
    By xforum142riidax in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-12-2011, 04:28 PM
  5. [SOLVED] Macro to extract data and paste to a new sheet
    By Les in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-11-2006, 05:15 AM
  6. macro to extract data of a selected sheet
    By TUNGANA KURMA RAJU in forum Excel General
    Replies: 1
    Last Post: 02-27-2006, 02:55 AM
  7. [SOLVED] macro to extract info and paste to a new sheet
    By Brad K. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2005, 07:06 PM

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