+ Reply to Thread
Results 1 to 7 of 7

Generate Rows by a rule

  1. #1
    Registered User
    Join Date
    09-16-2019
    Location
    Tehran
    MS-Off Ver
    2019
    Posts
    3

    Generate Rows by a rule

    Hello every one. I have a question about how to generate excel row by a specific rule. Let me explain with pictures:
    I have a long dataset like this:
    Screen Shot 2019-09-16 at 9.55.52 PM.png

    And I want to duplicate some rows (those that has the number column more than 1) to rows with the same cell's value by the value of number. Like the following picture:
    Screen Shot 2019-09-16 at 9.58.09 PM.png


    I would be thankful if you help me.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,720

    Re: Generate Rows by a rule

    You can use column H as a helper column to generate a cumulative sum of the number column (F), for example, put zero in H1 and this formula in H2:

    =IF(F2="","",F2+H1)

    Copy this down as far as required. Then in a separate sheet you can have an INDEX/MATCH formula in conjunction with the ROWS function to generate the expanded set of data.

    It would help if you attached a sample Excel workbook so that I could show you how to set this up.

    To do this, click on Go Advanced (below the Edit Window) while you are composing a reply, then scroll down to and click on Manage Attachments and the Upload window will open. Click on Browse and navigate to (and double-click) the file icon that you want to attach, then click on Upload and then on Close this Window to return to the Edit window. When you have finished composing your post, click on Submit Post.

    Don't try to use the Paperclip icon, as it doesn't work on this forum.

    Hope this helps.

    Pete

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Generate Rows by a rule

    ...and another pragmatic approach

    Copy all the data as many times as the highest repeat. In this example 5 in a repetitive list
    Then in a helper column (say H1) alongside the data

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    where column E is the food name column and F is the number of repeats.

    Copy H1 down the list of repeated examples, then autofilter for the "N" values, select those rows and delete them then remove the autofilter
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    09-16-2019
    Location
    Tehran
    MS-Off Ver
    2019
    Posts
    3

    Re: Generate Rows by a rule

    Quote Originally Posted by Pete_UK View Post
    You can use column H as a helper column to generate a cumulative sum of the number column (F), for example, put zero in H1 and this formula in H2:

    =IF(F2="","",F2+H1)

    Copy this down as far as required. Then in a separate sheet you can have an INDEX/MATCH formula in conjunction with the ROWS function to generate the expanded set of data.

    It would help if you attached a sample Excel workbook so that I could show you how to set this up.

    To do this, click on Go Advanced (below the Edit Window) while you are composing a reply, then scroll down to and click on Manage Attachments and the Upload window will open. Click on Browse and navigate to (and double-click) the file icon that you want to attach, then click on Upload and then on Close this Window to return to the Edit window. When you have finished composing your post, click on Submit Post.

    Don't try to use the Paperclip icon, as it doesn't work on this forum.

    Hope this helps.

    Pete
    Thanks for your reply. I have attached the excel file.

    sorry I didn't understand exactly what was your solution.
    Attached Files Attached Files

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,720

    Re: Generate Rows by a rule

    See attached file, where I have put zero in cell H1 of Sheet1 and this formula in H2:

    =IF(F2="","-",F2+H1)

    and then copied this down - the hyphens help to show where the formula is active, in case you add more data, and this gives a cumulative sum of the numbers.

    Then I created a second sheet with the same layout and used this formula in H2:

    =IF(ROWS($1:1)>MAX(Sheet1!$H:$H),"",MATCH(ROWS($1:1)-1,Sheet1!$H:$H)+1)

    This gives the row where each record can be found, and can be copied down as far as you need it (I've copied down to row 13 in this file). Then in A2 you can use this formula:

    =IF($H2="","",INDEX(Sheet1!A:A,$H2))

    which can be copied across and down as required, to display the appropriate fields for the expanded record set.

    Hope this helps.

    Pete
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-16-2019
    Location
    Tehran
    MS-Off Ver
    2019
    Posts
    3

    Re: Generate Rows by a rule

    Thank you so much. This solution is working very well for me.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,720

    Re: Generate Rows by a rule

    Glad to hear it.

    If that takes care of your original question, please take a moment to select Thread Tools from the menu above and to the right of your first post in this thread, and mark the thread as SOLVED.

    Also, since you are relatively new to the forum, you might like to know that you can directly thank those who have helped you by clicking on the small "star" icon located in the lower left corner of a post that you have found to be helpful (not just in this thread - for any post that has helped you). This also adds to the reputation of the poster (the small green bars in the poster's profile).

    Pete

+ 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. Create rule using date-range to generate cell header
    By Pancho1990 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 07-07-2017, 04:23 PM
  2. How to generate random number with rule?
    By Mihelherbiii in forum Excel General
    Replies: 13
    Last Post: 04-10-2016, 12:45 PM
  3. Replies: 1
    Last Post: 02-16-2016, 07:51 PM
  4. Replies: 6
    Last Post: 02-18-2015, 03:40 AM
  5. Copying a Conditional Format Rule from One Row to Many Rows
    By wongc61 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-25-2012, 06:11 PM
  6. Excel 2007 : Formula for muliplying rows as a rule
    By Paul_F in forum Excel General
    Replies: 4
    Last Post: 01-06-2009, 03:48 AM
  7. Deleting rows matching a rule
    By cmt_london in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-24-2007, 08:32 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