+ Reply to Thread
Results 1 to 9 of 9

Duplicate row and modify if a certain cell in the row meets condition

  1. #1
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Duplicate row and modify if a certain cell in the row meets condition

    Hi,

    I want a macro to look trough all cells in a column and for all cells that meets a certain condition it should duplicate that entire row and make adjustment to the new row and the original row.

    Why? I have a list (product name - source - volume) that I need to go through each month and for some products the source is not 100% Sweden as it sais in the table, but 70% Sweden and 30% Germany. So I manually find these products, duplicate the rows and, for Sweden multiply the volume with 70% and for Germany multiply the volume with 30%. Would love if a macro could do that for me!!

    The number of rows in the table changes from month to month.

    Please see attched example file.

    Many thanks,
    Martin
    Attached Files Attached Files
    Last edited by masben; 02-18-2015 at 11:20 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: Duplicate row and modify if a certain cell in the row meets condition

    What is the criteria to know that product B is 70% Swedish and 30% German. What will be the key determinant to discover this for your entire dataset?
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Re: Duplicate row and modify if a certain cell in the row meets condition

    Quote Originally Posted by alansidman View Post
    What is the criteria to know that product B is 70% Swedish and 30% German. What will be the key determinant to discover this for your entire dataset?
    Hi!

    Thanks for showing intrest in my problem. Sorry I havent replied until now - I have been travelling the last couple of weeks. There is no criteria... Product B is allways 70% Swedisch and 30% German. I just want to duplicate any rows with Product B and split the volume 70/30 on the two new rows.

    Thanks
    //Martin

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Duplicate row and modify if a certain cell in the row meets condition

    Perhaps like this?

    Please Login or Register  to view this content.
    Macro is based on the layout of your uploaded file i.e. "Product", "Source" and "Volume" assumed to be in columns "D", "E" and "F" and data starts in row 4.

    Alf

  5. #5
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Re: Duplicate row and modify if a certain cell in the row meets condition

    Quote Originally Posted by Alf View Post
    Perhaps like this?

    Please Login or Register  to view this content.
    Macro is based on the layout of your uploaded file i.e. "Product", "Source" and "Volume" assumed to be in columns "D", "E" and "F" and data starts in row 4.

    Alf
    Thanks Alf!
    This is excatley what I was looking for :-) Reputation added!

    Is it possible to modify the code so that more columns are multiplied with 0,7 and 0,3 respectively? I realised that I have two more columns that needs to be changed (col G - cost and col H - revenue) that I didn't include in the example...

    Thanks again,
    Martin

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Duplicate row and modify if a certain cell in the row meets condition

    Yes that should be possible. Assuming earliar layout with the excption that col G an H are added it could be done like this

    Please Login or Register  to view this content.
    Code could certainly be better "written" but as I'm soon of to Gothenburg I'm a bit stressed for time.

    Thanks for feedback and rep.

    If this solves you problem don't forget to mark thread "Solved"

    Alf

    Ps
    To mark your thread solved do the following:
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

  7. #7
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Duplicate row and modify if a certain cell in the row meets condition

    Having tested this macro a bit more I see one problem. There is the row where you sum the totals and as this macro uses "shift:=xlDown" and if D4 = B then the sum range is shifted down one row from row 4 to row 5.

    All other insert of rows will not affect the "sum" formula as it will adjust to this automatically. So in order to adjust for the case that D4 = B add the following lines to the macro just after the "Next" line.

    Please Login or Register  to view this content.

    Alf

  8. #8
    Forum Contributor
    Join Date
    11-20-2012
    Location
    stockholm
    MS-Off Ver
    Excel 2010
    Posts
    123

    Re: Duplicate row and modify if a certain cell in the row meets condition

    Quote Originally Posted by Alf View Post
    Having tested this macro a bit more I see one problem. There is the row where you sum the totals and as this macro uses "shift:=xlDown" and if D4 = B then the sum range is shifted down one row from row 4 to row 5.

    All other insert of rows will not affect the "sum" formula as it will adjust to this automatically. So in order to adjust for the case that D4 = B add the following lines to the macro just after the "Next" line.

    Please Login or Register  to view this content.

    Alf
    Thanks for all your help Alf!
    This macro will save a lot of time for me so I really apriciate it!! TACK!!

    Ha det bra!
    //Martin

  9. #9
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Duplicate row and modify if a certain cell in the row meets condition

    Det e lugnt! Bara kul att kunna hjälpa till lite.

    Alf

+ 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. [SOLVED] Add borders to row if first cell meets condition
    By bullshot25 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2013, 10:14 AM
  2. Replies: 3
    Last Post: 04-20-2013, 09:55 PM
  3. [SOLVED] Copy Cells Where Another Cell On Same Row Meets Condition
    By marshak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-25-2013, 08:36 PM
  4. image/picture appear if a cell meets a certain condition?
    By rbiamonte in forum Excel General
    Replies: 1
    Last Post: 08-26-2008, 03:36 PM
  5. Find value for a cell that meets a condition?
    By lanix in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-06-2007, 03:57 AM

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