+ Reply to Thread
Results 1 to 7 of 7

Show/Hide Group entire Columns in Range with vba

Hybrid View

emorej Show/Hide Group entire... 10-31-2022, 09:16 AM
Squeaky Re: Show/Hide Group entire... 11-01-2022, 10:03 AM
emorej Re: Show/Hide Group entire... 11-02-2022, 03:35 AM
AliGW Re: Show/Hide Group entire... 11-02-2022, 03:43 AM
emorej Re: Show/Hide Group entire... 11-02-2022, 01:00 PM
ByteMarks Re: Show/Hide Group entire... 11-03-2022, 11:54 AM
beyond Excel Re: Show/Hide Group entire... 11-03-2022, 01:56 PM
  1. #1
    Registered User
    Join Date
    10-10-2022
    Location
    Germany
    MS-Off Ver
    365
    Posts
    31

    Show/Hide Group entire Columns in Range with vba

    Hello dear friends. I am a little desperate.
    I have written a VBA code which should hide and show me my comment columns. Since these can change often, it is too complicated for me with my solution, because I always have to change the exact range.
    Now I have come up with the idea to hide and show all columns which are grouped from column D for example.
    My problem: I get it done with 2 different codes and thus 2 different buttons, but not with one button.
    I have already read through everything on outline.showlevels, but have not found a solution.
    In my attached file the red button should show/hide the columns F and G I and J M and N P and Q (if they are shown). I have attached my code so far, but it is too complicated for me as described above.
    I would be very happy about help!!!


    i just saw that i can't get the marko attached. So my manual too complicated macro so far:

    
    Sub HideColumnsRows()
    
    If Range("F:G,I:J,M:N,P:Q").EntireColumn.Hidden = True Then
    'Makes all hidden rows and columns in the active sheet unvisible.
        Range("F:G,I:J,M:N,P:Q").EntireColumn.Hidden = False
    
    Else
    
        Range("F:G,I:J,M:N,P:Q").EntireColumn.Hidden = True
    
    End If
    
    End Sub
    Last edited by emorej; 11-02-2022 at 04:35 AM.

  2. #2
    Forum Contributor
    Join Date
    08-12-2020
    Location
    Atlanta, Georgia
    MS-Off Ver
    Office 16
    Posts
    245

    Re: Show/Hide Group entire Columns in Range with vba

    Hi emorej, when I put the code in and assign the macro to the button, in one click it will hide the columns and then in one click it will unhide the columns. I do not understand the problem. When you assign the macro you will need to save this document as a .xlsm file.

  3. #3
    Registered User
    Join Date
    10-10-2022
    Location
    Germany
    MS-Off Ver
    365
    Posts
    31

    Re: Show/Hide Group entire Columns in Range with vba

    Hello and thank you for the answer. Yes my code works but I want a simpler one. Because in my code I have selected all columns individually. But I want my code to hide and show the columns after the groupings. So as described above.
    Last edited by AliGW; 11-02-2022 at 03:44 AM. Reason: Please DON'T quote unnecessarily!

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,040

    Re: Show/Hide Group entire Columns in Range with vba

    Administrative Note:

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code] [/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    10-10-2022
    Location
    Germany
    MS-Off Ver
    365
    Posts
    31

    Re: Show/Hide Group entire Columns in Range with vba

    Quote Originally Posted by AliGW View Post
    Administrative Note:

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code] [/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Hello and sorry again! I changed it in the morning.

  6. #6
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,079

    Re: Show/Hide Group entire Columns in Range with vba

    Would it work to hide/unhide based on the heading being "Comment" ?

    Sub HideUnhide()
    Dim rngColumns As Range, f As Range
    Dim fa As String
    
    With Rows(2)
        Set f = .Find(what:="Comment", lookat:=xlWhole, LookIn:=xlFormulas)
        If Not f Is Nothing Then
            fa = f.Address
            Do
                If rngColumns Is Nothing Then
                    Set rngColumns = f
                Else
                    Set rngColumns = Union(rngColumns, f)
                End If
                Set f = .FindNext(f)
            Loop While Not f Is Nothing And fa <> f.Address
        End If
    End With
    
    If Not rngColumns Is Nothing Then rngColumns.EntireColumn.Hidden = Not rngColumns.EntireColumn.Hidden
    End Sub

  7. #7
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Show/Hide Group entire Columns in Range with vba

    Hi, emorej.
    The method I'll show you next doesn't require the columns to be grouped:

    Sub Hide_unHide()
    Dim a, Q%, i&, b, R%
    a = Range("a2", Cells(2, [a1].SpecialCells(xlLastCell).Column)).Value
    Q = UBound(a, 2): ReDim b(1 To Q)
    For i = 6 To Q
      If a(1, i) = "Comment" Then
        R = 1 + R: b(R) = Cells(2, i).Address & ":" & Cells(2, i).Address
      End If
    Next
    ReDim Preserve b(1 To R): b = Join(b, ",")
    With Range(b).EntireColumn
      If .Hidden = True Then .Hidden = False Else .Hidden = True
    End With
    End Sub

+ 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. Macro to "Group" (hide/show toggle) each marked columns based on an array list.
    By Hyflex in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-07-2016, 09:31 PM
  2. 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
  3. [SOLVED] Show/Hide Rows Columns based on value in named range
    By Andrew-Mark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2016, 07:13 AM
  4. Show/Hide Group of shapes while keeping individual shape visibility settings
    By Voldenite in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2015, 03:12 AM
  5. [SOLVED] Macro to hide entire columns within range if cells within range are blank
    By graphicgoose in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2013, 08:26 PM
  6. Show entire row from Master Sheet if any of the columns are within a date range
    By chriswathen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2012, 05:44 PM
  7. [SOLVED] Hide and show a group of worksheets
    By dreamkeeper in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2006, 04:10 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