Results 1 to 1 of 1

Macro to "Group" (hide/show toggle) each marked columns based on an array list.

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-07-2010
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    358

    Macro to "Group" (hide/show toggle) each marked columns based on an array list.

    Hi,

    I am wanting to make a macro to use Excel's "group" feature/tool as found in Data > Group but via a macro, examples of the function that I am wanting to use:

    Columns("A:B").Columns.Group
    I want to define columns based on a string such as:
    GROUPCOLUMNS = Array("Title 4", "E 8", "E 4", "E 3", "E 2", "E 1")
    For the first one in the list "Title 4" that one is a column on it's own which is easy to do.

    The hard part is when it gets to the column titled "E 8" it needs to detect that this column is marked to be grouped, check the columns to the right until a column is no longer being "matched" in the GROUPCOLUMNS variable and hide them as a single group, but then when it cycles to the next column titled "E 4" it should skip this one as it's already been "grouped"

    In my attached document, you can see the easy visual view of how it would group them by comparing Sheet 1 and Sheet 2

    I'd prefer to stick with this sort of structure macro as someone else made as it's nice and easy to understand for me.

    Sub GROUPING()
    
        GROUPCOLUMNS = Array("Title 4", "E 8", "E 4", "E 3", "E 2", "E 1"
    
        Set rng = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
        For Each a In rng.SpecialCells(xlCellTypeConstants).Areas
            With a.CurrentRegion
                Set r = .Rows(1)
                For j = 1 To r.Columns.Count
                     '-----------------------------------------------------------------------------------------
                     If IsInArray(r.Cells(j).Value, GROUPCOLUMNS ) Then
                     ' Not sure...
                     End If
                    '-----------------------------------------------------------------------------------------
               Next j
            End With
        Next a
        
    End Sub
    Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
      IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
    End Function
    I'd greatly appreciate some advice.
    Attached Files Attached Files
    Last edited by Hyflex; 07-07-2016 at 09:39 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to "Group" (hide/show toggle) each dataset & marked columns.
    By Hyflex in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-02-2016, 01:14 PM
  2. VBA CODE TO hide/unhide based on validation list "YES","NO"
    By SUDI in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2014, 06:03 PM
  3. How to show Items marked with "hide" in the PageField dialog
    By vdr60 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2014, 05:06 PM
  4. [SOLVED] Hide Columns based on level of access e.g. if "Read Only" Hide G:G
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-16-2013, 06:10 AM
  5. create links to check boxes marked "good" fair"and "bad"
    By pjb in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-19-2006, 09:25 PM
  6. Replies: 0
    Last Post: 02-01-2006, 03:35 AM
  7. Replies: 8
    Last Post: 01-04-2006, 12:10 PM

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