+ Reply to Thread
Results 1 to 7 of 7

Macro needed to hide/unhide alternative columns in a spreadsheet

  1. #1
    Registered User
    Join Date
    04-27-2017
    Location
    Plymouth
    MS-Off Ver
    10
    Posts
    2

    Macro needed to hide/unhide alternative columns in a spreadsheet

    Hi

    I am new to this and need some expert help, though to most of you this will be straight forward!

    I've used the code I found below which works perfectly for a range of columns, except I need to adapt it to hide alternate columns in my sheet. For example I want to hide G, I, K and so on until BU.

    Sub HideStuff()
    With Columns("G:M")
    If .Hidden Then
    .Hidden = False
    Else
    .Hidden = True
    End If
    End With
    End Sub

    Thank you in advance. H

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Macro needed to hide/unhide alternative columns in a spreadsheet

    Hi hno18

    Welcome....
    In future please view the forum rules before posting. Your post does not comply with rule #3.
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the [#] button at the top of the post window.
    Please Login or Register  to view this content.
    Or
    Please Login or Register  to view this content.
    Last edited by Sintek; 04-28-2017 at 08:52 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro needed to hide/unhide alternative columns in a spreadsheet

    I think Sintek missed the Unhide bit, so
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Macro needed to hide/unhide alternative columns in a spreadsheet

    @ Richard....True Thanks.... I guess I misunderstood OP request.
    For example I want to hide G, I, K and so on until BU.

  5. #5
    Registered User
    Join Date
    04-27-2017
    Location
    Plymouth
    MS-Off Ver
    10
    Posts
    2

    Re: Macro needed to hide/unhide alternative columns in a spreadsheet

    Hello,

    Sorry for not correctly pasting in the code. I hadn't even noticed the rules. Accept my apologies!

    Thank you all for replying. However, when I put the code in Richard and run the macro it keeps coming up with the message 'object required'.

    Not sure what this means or what I am doing wrong?

    My sheets so far are named 'APR', 'MAY' and 'JUN'. Does that make a difference.

    Thank you. H

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Macro needed to hide/unhide alternative columns in a spreadsheet

    To expand the OP code to the whole worksheet, I'd use
    Please Login or Register  to view this content.
    To start the "every other column hidden" process, one could use
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro needed to hide/unhide alternative columns in a spreadsheet

    Quote Originally Posted by hn018 View Post
    Hello,

    Sorry for not correctly pasting in the code. I hadn't even noticed the rules. Accept my apologies!

    Thank you all for replying. However, when I put the code in Richard and run the macro it keeps coming up with the message 'object required'.

    Not sure what this means or what I am doing wrong?

    My sheets so far are named 'APR', 'MAY' and 'JUN'. Does that make a difference.

    Thank you. H
    The code I gave you doesn't use sheet tab names. As an aside it's not considered good practice to use tab names since they are too easily changed. My code uses the VBA sheet code name. The code assumes that the sheet in question has the VBA code name of 'Sheet1'. Obviously if you've deleted or changed this at some time you'll get that message. Look to see what the VBA sheet code name is - you can see that in the VBA Project Window where yuo see references like

    Sheet1(Sheet1)

    Where the string in the () parentheses is the tab name.

+ 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. [SOLVED] A macro to hide certain columns, and then unhide them
    By davidx in forum Excel General
    Replies: 9
    Last Post: 01-08-2015, 05:38 AM
  2. [SOLVED] Hide/ unhide rows in spreadsheet with macro
    By bryan155 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-19-2013, 10:09 AM
  3. [SOLVED] Macro that will hide and unhide columns
    By johnw993 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2013, 02:59 AM
  4. Macro to hide/unhide columns
    By IcemanFTW in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-08-2011, 10:41 AM
  5. Macro to hide/unhide columns
    By ScottBNYM in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2009, 03:20 PM
  6. Hide or unhide columns with one macro
    By simonsmith in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-23-2008, 10:13 PM
  7. [SOLVED] Macro to hide or unhide columns
    By Chance224 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2005, 06:06 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