+ Reply to Thread
Results 1 to 6 of 6

Macro - Grouping rows with constraints

  1. #1
    Registered User
    Join Date
    04-21-2008
    Posts
    11

    Macro - Grouping rows with constraints

    Hi all

    I have to group rows with some limitations:
    a. Each group cannot exceed 4 rows (but can be less)
    b. A group may "spillover" to the next, except if the next group can fit itself perfectly within a new group itself - :'(

    The logic is a little strange.

    I tried to count the number of instances then divide by the 4, but then got all tangled up because I got a number which defined how many groups was required, but not which group the rows were in!

    Team Leads.jpg

    Have no clue how to approach this.

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Macro - Grouping rows with constraints

    Maybe :
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by karedog; 09-20-2020 at 06:35 AM.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Registered User
    Join Date
    04-21-2008
    Posts
    11

    Re: Macro - Grouping rows with constraints

    Hi! Thank you so much for this. I'll try it out and report back.

    Just wanted to ask something:
    Please Login or Register  to view this content.
    We define "1 To 3" because it's a group of 4 right? If this changes next time to a different number like 5, will it then be "1 To 4"?

    Thanks again!

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Macro - Grouping rows with constraints

    You are welcome and thanks for the reps given.

    No, 1 to 3 here, is because the macro works in 3 phase :
    Phase 1 : Any rows that can be grouped, because they have same data, are fall in this phase (in above example, they are rows 2:5, 10:13, 15:18)
    Phase 2 : Any rows that can be grouped, not have same data (remaining of phase 1) but the members is enough to form a new group , are fall in this phase (in above example, they are rows 6:9)
    Phase 3 : Any other rows remaining of phase 1 and 2, fall in this phase

    I have modified the code on post #2, by defining :
    Const nGroup As Long = 4
    so the macro can be adjusted to any number you want, just try to change this value to see the result.

  5. #5
    Registered User
    Join Date
    04-21-2008
    Posts
    11

    Re: Macro - Grouping rows with constraints

    Hi there!

    Thanks so much for explaining. I really appreciate it!

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Macro - Grouping rows with constraints

    You are welcome Jaime, and don't forget to mark this thread as solved.

    Regards

+ 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. VBA/Macro Add new rows with format based on year grouping
    By COfire in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-16-2019, 11:00 AM
  2. [SOLVED] Create a Grouping Macro, using an Outline column to quickly group rows
    By JimmyWilliams in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-31-2017, 10:29 PM
  3. VBA Solver Macro which repeats accross multiple collumns with IF constraints
    By s.patelupi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-19-2016, 10:01 AM
  4. [SOLVED] One Macro with multiple solver each with different constraints
    By Alyotter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-02-2013, 10:59 AM
  5. Excel Macro to Group by bold subtotal rows (multiple levels of grouping)
    By aozorap in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-22-2013, 03:13 PM
  6. grouping rows
    By mmcoordes in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 12-11-2012, 07:46 AM
  7. [SOLVED] macro for 4 constraints in autofilter
    By Gus in forum Excel General
    Replies: 1
    Last Post: 08-04-2005, 09:05 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