+ Reply to Thread
Results 1 to 10 of 10

Excel VBA code to group rows based on a cell value

  1. #1
    Registered User
    Join Date
    09-16-2019
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    48

    Excel VBA code to group rows based on a cell value

    Hello,

    i have a list of items organized in : project, activities and sub-activities (Column "A"). They have a specific index - level number, Project = 0, Activity = 1, Sub-activity = 2. These numbers are in column "B".

    The data looks like this :

    Column "A"

    Example Project
    Activity 1
    Sub-activity 1
    Sub-activity 2
    Activity 2

    Column "B"

    0
    1
    2
    2
    1

    What i would like to have is, when the macro runs, all the level 2 should group under the level 1 and all the level 1 (with the level 2 grouped) should group under level 0.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Excel VBA code to group rows based on a cell value

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Registered User
    Join Date
    09-16-2019
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    48

    Re: Excel VBA code to group rows based on a cell value

    I explained well my problem and my needs, i don't think it's necessary to upload 2 sample workbooks.
    If anyone could help me that's fine, otherwise I'll try another forum.

  4. #4
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Excel VBA code to group rows based on a cell value

    One method
    Please Login or Register  to view this content.
    But a simple sort would suffice
    Please Login or Register  to view this content.
    Last edited by nigelog; 09-23-2019 at 04:34 AM.

  5. #5
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Excel VBA code to group rows based on a cell value

    Quote Originally Posted by Lomoo View Post
    I explained well my problem and my needs, i don't think it's necessary to upload 2 sample workbooks.
    If anyone could help me that's fine, otherwise I'll try another forum.
    If you don't care about our members helping you for free on their spare time having to create a sheet for testing themselves, that is your privilege.

  6. #6
    Registered User
    Join Date
    09-16-2019
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    48

    Re: Excel VBA code to group rows based on a cell value

    Thank you Nigelog for the answer. I tryed but it changed the order of the level's number. I want to maintain the same order and compress data of column "A" with level 2 into level 1, the small + in the left panel should also appear.

    Maybe this could help you :

    Project 1 0
    Act 1 1
    Sub-act 1 2
    Sub-act 2 2
    Act 2 1
    Act 3 1

    When macro start, this should happen :

    (-) Project 1 0
    (-) Act 1 1
    Sub-act 1 2
    Sub-act 2 2
    (+) Act 2 1
    (+) Act 3 1

  7. #7
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Excel VBA code to group rows based on a cell value

    Makes no sense to me. Maybe someone else could help

  8. #8
    Registered User
    Join Date
    09-16-2019
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    48

    Re: Excel VBA code to group rows based on a cell value

    I added an attachment, try to see that code. It almost work.
    Attached Files Attached Files

  9. #9
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Excel VBA code to group rows based on a cell value

    Workbook does not help in explaining what you require
    Data does not even contain what you have in your posts

    Make up cells which represent data BEFORE macro and then AFTER macro so that your line of thought can be followed

  10. #10
    Registered User
    Join Date
    09-16-2019
    Location
    Italy
    MS-Off Ver
    2016
    Posts
    48

    Re: Excel VBA code to group rows based on a cell value

    Quote Originally Posted by nigelog View Post
    Workbook does not help in explaining what you require
    Data does not even contain what you have in your posts

    Make up cells which represent data BEFORE macro and then AFTER macro so that your line of thought can be followed
    I will solve it myself, no problem.

+ 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. Group rows based on cell value
    By russkris in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-28-2017, 11:43 PM
  2. Macro to Group (Outline) rows based on cell values
    By excelatnothing in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-22-2015, 02:13 AM
  3. Group rows based on part of cell value
    By dispro14 in forum Excel General
    Replies: 3
    Last Post: 11-19-2014, 06:47 AM
  4. Replies: 1
    Last Post: 02-10-2014, 10:26 PM
  5. [SOLVED] How to group rows based on one cell and get the sum of second cells
    By NoBullMan in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 12-13-2013, 01:07 PM
  6. [SOLVED] VBA Code to Group Rows Based on Cell Contents
    By Pliskers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-10-2006, 03:29 AM
  7. [SOLVED] excel: How can I color code rows based on a value in a cell?
    By Parker1333 in forum Excel General
    Replies: 2
    Last Post: 02-01-2005, 07:06 PM

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