+ Reply to Thread
Results 1 to 12 of 12

macro to create copy of template based on two criteria and paste data from master sheet

  1. #1
    Registered User
    Join Date
    04-18-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010
    Posts
    11

    macro to create copy of template based on two criteria and paste data from master sheet

    I have a master sheet which contains several line items and 4 deal templates. I want a macro to loop therough each line item in master sheet and create copy of 1 of the 4 templates depending upon 2 conditions ie asset type and trensaction type ie buy or sell.

    Any help is really appreciated.
    Attached Files Attached Files

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi, deepsi1,

    you should clarify if you want to copy the data into the Columns A to D of the new sheets or into the yellow fields (if so then why are there 2 for Name in the Gsec sheets?).

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    04-18-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi,

    I want to copy the data in Sheet1 in Columns A to D in New Sheets in Yellow Marked Fields in newly copied sheets.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi, deepsi1,

    give this a try:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    04-18-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi Holger,

    That works great. Almost what i wanted. But a slight change is required. I am attaching the file with the result.As you will see in sheets M17 and M18 the units and prices were not pasted in Correct Position. The code used the position for Gsec Pur and Gsec Sale sheets thought they were not. (they are in different rows in GSec sheets and Non Gsec Sheets)
    I request you to please edit it for me.

    But otherwise a marvelous code.
    Thanks.
    Attached Files Attached Files

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi, deepsi1,

    please alter the code like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    04-18-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi Holger,

    Sorry to bring this up late, I need a little extra bit.
    I may have to run the code again and again as data comes to me in bits and parts. So what I need is when i add data to sheet 1, if the sheet for deal id already exists it should skip to next line , such that it will move to additional data in sheet1 when i run the macro 2nd or 3rd time.

    Thanks a Ton. The modification worked perfectly.

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi, deepsi1,

    either place a boolean value next to the data already worked on or use either a loop or try to activate the sheet to find out what action needs to be taken (skip or add a new one). IŽd go with the additional information in the original Master.

    Ciao,
    Holger

  9. #9
    Registered User
    Join Date
    04-18-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi Holger,

    In case I add additional columns (fields) in Sheet1 , say column G and H containing additional values that i need to paste in the Deal Sheets in Cell F7 & G7, how do I edit the code.

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi, deepsi1,

    add the cells to copy and paste in the Arrays:
    Please Login or Register  to view this content.
    The copying will be done by the length of the Arrays but the cells would need to be directly side by side (no other data in the columns from A to F). If you want other values in there you would need another array holding the columns from which to take and in which order.

    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    04-18-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi Holger,

    That was really quick. You are brilliant. I tried it and it worked perfectly.
    Can I request you again to provide me something for "if the sheet for deal id in Sheet1 already exists it should skip to next line , such that it will move to additional data in sheet1 when i run the macro 2nd or 3rd time.". The reason being that even though I will get the data in Parts I receive consolidated data not just the new line items. I know the code will become heavy and too complex, But I would really like to see if it can be done.

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: macro to create copy of template based on two criteria and paste data from master shee

    Hi, deepsi,

    maybe use another Boolean for the check of whether the sheet already exists or needs to be copied. Code is untested:
    Please Login or Register  to view this content.
    Evaluate could be used to check the existence of the sheet instead of activating the sheet like shown in the Function above.

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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