+ Reply to Thread
Results 1 to 2 of 2

Macro to hide columns based on contents

Hybrid View

  1. #1
    Registered User
    Join Date
    05-29-2010
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    58

    Macro to hide columns based on contents

    Hi I'm looking for a macro that will hide any columns that contain a certain character, when a button is clicked.

    In rows G:CH I have either an X or nothing in row 1. I would like the click of the button to hide all columns marked with an X - I don't want this to be automatic though. Is this possible?

    Thanks in advance for any help.

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Macro to hide columns based on contents

    Hi Samcdavies,

    Try using below code:-

    Sub hide()
    
    i = Range("iv1").End(xlToLeft).Column
    Cells(1, 1).Select
    For n = 1 To i
    If Selection.Value = "x" Then
    Selection.EntireColumn.Hidden = True
    Selection.Offset(0, 1).Select
    Else
    Selection.Offset(0, 1).Select
    End If
    Next
    
    End Sub

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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