Group Every Nth Row

  • Hi everybody,


    I'm very illiterate with Excel, but I'm sure you guys will be able to help me. Here my situation:


    I have an Excel sheet with one column (column A) and I have 503 000 data rows. In the first 503 rows I will need to insert the data group1. The next 503 rows, I will need to insert the data group2. The data always increment by 1 every 503 rows.


    I could do it manually for few groups, but I need to create 1000 groups (503 000 rows). So you can imagine the load of work if I would do that manually.


    Does anyone can explain me how to create a macro or anything that could automate this?


    Thanks everyone!


    Ps: Im using Excel 2007 that support more than 1 million rows vs the old Excel versions which is a max of 64 000 rows

  • Re: Increment By 1 The Variable in Every 503 Rows


    As a macro-free solution, in column B, you can put =MOD(ROW(),503)=0 and drag that down. Apply filters to the sheet and filter to TRUE. Highlight all 1000 rows, hit Ctrl+; to select only visible cells, then Alt, I, R to insert rows. Then delete column B.

  • Re: Increment By 1 The Variable in Every 503 Rows


    Quote from darkyam

    As a macro-free solution, in column B, you can put =MOD(ROW(),503)=0 and drag that down. Apply filters to the sheet and filter to TRUE. Highlight all 1000 rows, hit Ctrl+; to select only visible cells, then Alt, I, R to insert rows. Then delete column B.


    Hello Darkyam,


    Thank for your quick reply, but Im confuse with your explanations:


    1. As you recommendeded I have put =MOD(ROW(),503)=0 in cell B1. In B1 cell, it says now "false". Is it normal? You also said to drag that down, but until what cell?


    2. I feel pretty newbie, but can you tell me how do you "Apply Filters" and enable them to "True"?


    3. You said to highlight all the 1000 rows. I just want to make sure with you, because I have to do that on 503 000 rows. Where did you get the 1000 rows, Im confuse


    4. I need to have the text "group1" from A1 to A503, then the text "group2" from A504 to A1027, until "group1000". However, I don't see this step on your macro.


    Sorry, for all the newbie questions and thank again for your help

  • Re: Increment By 1 The Variable in Every 503 Rows


    1. Yes, it is normal. It will return either True or False. You would drag this down through all 503,000 rows.
    2. On the Home tab, toward the right is a sort and filter button. Hit Ctrl+A, then this button, then select Filter. In B1, filter to TRUE.
    3. Step 2 will give you 1,000 rows as the formula will be true only 1000 times.
    4. This is not a macro; a macro would do this all automatically. You did not request this text to be entered in your original post. If you need that as well, I could suggest another couple of steps, but you would probably be better off going for a macro at this point. I'd help, but I'm not good enough to do the second part of what you want yet.

  • Re: Increment By 1 The Variable in Every 503 Rows


    Perhaps this will help you.


    I have attached a sample spreadsheet that shows a method of achieving your goal.


    create a column to the right with the following formula =IF(CELL("row",A512)=$D$2,$D$2,0)
    Where D2 is equal to 512


    over one more column place the formula =IF(B512=$D$2,1,0) Format the cells in the column with a custom format that is equal to: "Group" #;[=0]#;General


    For row 1024 and beyond the formula for the first column would be =IF(CELL("row",A1024)=(B1024+$D$2),B1024+$D$2,0)


    and the second column, =IF(B1024=$D$2+B1024,1+C1024,0)


    after you have copied the second 2 formulas all the way down, select the 2 columns and copy the values then delete the first column.


    Regards,


    -Dude 8-)



    P.S. For some reason i put 512, just replace with the correct number

  • Re: Increment By 1 The Variable in Every 503 Rows


    Try this



    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: Increment By 1 The Variable in Every 503 Rows


    ah.. Bill,


    Much better, macros are the way to go for this one.
    Unfortunately my macro skills are slim to none.


    Good Job.


    -Dude 8-)

  • Re: Increment By 1 The Variable in Every 503 Rows


    Thanks Dude,


    this is the place to learn VBA for sure

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!