Results 1 to 2 of 2

Thread: VBA Help - Ungrouping Named Range Columns based on Variable
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular Johnny Thunder's Avatar
    Join Date
    Apr 2010
    Post Thanks / Like
    5 Post(s)
    0 Thread(s)

    Exclamation VBA Help - Ungrouping Named Range Columns based on Variable

    Hello All,

    I am working on a project that will Group/Ungroup specific columns based on a loop. for ease of maintenance I have created Named Ranges for the groupings to Expand or collapse the groupings based on a variable in a list.

    Here is the list


    1DivisionsNamed RangeGrouping Level
    2Domestic TheatricalDomTheat3
    3International TheatricalIntTheat3
    4Domestic Syndication 3
    5Domestic Cable Distribution 3
    6International Syndication 3
    7Domestic Licensing 3
    8International Licensing 3
    9Domestic Home Video 3
    10International Home Video 3
    11Domestic Digital Distribution 3
    12International Digital Distribution 3
    13Games 3

    Excel tables to the web >> Excel Jeanie HTML 4

    I have gathered some code from a user on another forum with a similar project but this code does not seem to work and I continue to get an error:

    Error 1004: Unable to Set ShowDetail property to Range Class

    Sub TestHideOrShowDetail()
    Dim ws As Worksheet, rng As Range
    Set ws = ActiveSheet
    Set rng = ws.[DomTheat]                    'Named Range "DomTheat" is columns CP:DS on my activesheet
    HideOrShowDetail DetailRange:=rng, ShowDetail:=True
    End Sub
    Sub HideOrShowDetail(ByRef DetailRange As Range, Optional ByVal ShowDetail As Boolean = False)
    Dim rngrow As Range
    For Each rngrow In DetailRange.Rows
        rngrow.ShowDetail = True '--------------------------------Error line
    Next rngrow
    End Sub
    Any ideas what the issue is?

    I still need to also create a loop that will look at my list and loop thru each named range in the list. For simplicity I have only created two named ranges.

    Please follow the forum Rules and Guidelines

    To post a screenshot try one of these links

    MrExcel HTML Maker, RoryA addin (Win & Mac) or Borders-Copy-Paste

  2. #2
    Board Regular
    Join Date
    Jan 2015
    Post Thanks / Like
    8 Post(s)
    0 Thread(s)

    Default Re: VBA Help - Ungrouping Named Range Columns based on Variable


    I would not use an extra function for hiding details, you can make it on one line

    'To group columns of named Range "DomTheat" from another sheet    
        Application.Goto [DomTheat]
    'To hide all details of all grouped columns of activesheet
        ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
    'Show details of "DomTheat"
        ActiveSheet.Columns([DomTheat].Column).ShowDetail = True
    'Hide detais of "DomTheat"
        ActiveSheet.Columns([DomTheat].Column).ShowDetail = False
    Last edited by Kamolga; Nov 4th, 2018 at 06:15 AM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts