Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Macro that will HIDE and UNHIDE columns

  1. #1
    Board Regular Chris The Rock's Avatar
    Join Date
    Feb 2002
    Location
    Longmont, CO
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I have a work book with many columns. Each column represents a new day.

    Because this workbook will be used for a long time, I've had to include far more columns than I presently need, so many of the columns do not contain any data. At any one time, I'd like only 10 columns to be visible.

    What I'd like to do is have a macro button that the user can click that will UNhide the next 4 columns to the right, while hiding the 4 leftmost visible columns, maintaining 10 visible columns.

    I can explain this better if needed, but these are the basics.
    "Never go in against a Sicilian when death is on the line!"

  2. #2
    Board Regular Chris The Rock's Avatar
    Join Date
    Feb 2002
    Location
    Longmont, CO
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Is this hard to do?

    [ This Message was edited by: Chris The Rock on 2002-03-15 11:43 ]

  3. #3
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    This should work (its not great coding though):
    Sub HideColumns()
    'assumes only 10 columns are showing to begin
    'hides first 4 columns
    Windows(1).VisibleRange.Cells(1, 1).Select
    Range(Selection, ActiveCell.Offset(0, 3)).Select
    Selection.EntireColumn.Hidden = True
    'unhides next 4 columns
    Selection.End(xlToRight).Select
    ActiveCell.Offset(0, 1).Select
    Range(Selection, ActiveCell.Offset(0, 3)).Select
    Selection.EntireColumn.Hidden = False
    End Sub

    Hope this helps.
    Kind regards, Al.

  4. #4
    Board Regular Chris The Rock's Avatar
    Join Date
    Feb 2002
    Location
    Longmont, CO
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Al,
    Thanks for your help. I took the basic idea from your example, and formed it into exactly what I needed.
    Again, many thanks.
    "Never go in against a Sicilian when death is on the line!"

Some videos you may like

User Tag List

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
  •