+ Reply to Thread
Results 1 to 8 of 8

Hide non ajacent colums with a Macro

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Halstead
    MS-Off Ver
    Excel 365
    Posts
    240

    Hide non ajacent colums with a Macro

    I am trying to hide non adjacent columns in a spreadsheet with a macro, I can select the columns no problem and hide them but when I assign the macro I have recorded to a button it hides all the colums between the ones I have selected as well.

    Does anyone no what I am doing wrong and how to fix it.

    The Macro I have recorded is

    Sub Hide_all()
    '
    ' Hide_all Macro
    '

    '
    Range("N:N,K:N,C:C").Select
    Range("C1").Activate
    Selection.EntireColumn.Hidden = True
    ActiveWindow.SmallScroll ToRight:=-2
    End Sub
    Last edited by Shazz; 02-01-2013 at 10:40 AM. Reason: Solved

  2. #2
    Forum Contributor
    Join Date
    02-24-2011
    Location
    Belfast, N. Ireland
    MS-Off Ver
    Excel 2010
    Posts
    103

    Re: Hide non ajacent colums with a Macro

    Shazz,

    Just looking there but your code shows that you select Row C and everything from Row K to Row N. If you want to hide those 3 rows (C, K & N), try the following in place of your code.
    Sub Hide_all()
    ' Hide_all Macro
    Range("N:N,K:K,C:C").EntireColumn.Hidden = True
    End Sub
    Mowgli

  3. #3
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Halstead
    MS-Off Ver
    Excel 365
    Posts
    240

    Re: Hide non ajacent colums with a Macro

    Unfortunately this is also hiding the whole lot as well, I need to Hide C, K, L, M and N.

    Shazz

  4. #4
    Forum Contributor
    Join Date
    02-24-2011
    Location
    Belfast, N. Ireland
    MS-Off Ver
    Excel 2010
    Posts
    103

    Re: Hide non ajacent colums with a Macro

    Shaz,

    I changed the Range to hide Column C and Columns K to N (as opposed to the rows which I misstyped earlier). the following code works fine on my machine, can you upload an example to see if anything else is playing havoc with it? I currently have all Columns except C, K, L, M and N visible when I run Hide_all.

    Sub Hide_all()
    ' Hide_all Macro
    Range("C:C,K:N").EntireColumn.Hidden = True
    End Sub
    Mowgli

  5. #5
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Halstead
    MS-Off Ver
    Excel 365
    Posts
    240

    Re: Hide non ajacent colums with a Macro

    Hi Mowgli,

    I now have the Hide Macro working but now the unhide macro is not working, something strange is happening here, but it works if I go to the developer tab and run it through there.

    Attached is a copy example of the spreadsheet.

    Your help is very much apprciated.

    Shazz
    xx
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    02-24-2011
    Location
    Belfast, N. Ireland
    MS-Off Ver
    Excel 2010
    Posts
    103

    Re: Hide non ajacent colums with a Macro

    Hey Shazz,

    Try this, I reassigned the unhide macro to the button and simplified the unhide macro a little. Seems to work ok but let me know

    Mowgli

    Example 1.xls

  7. #7
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Halstead
    MS-Off Ver
    Excel 365
    Posts
    240

    Re: Hide non ajacent colums with a Macro

    Perfect, Thank so much you are a star.

    Shazz

  8. #8
    Forum Contributor
    Join Date
    02-24-2011
    Location
    Belfast, N. Ireland
    MS-Off Ver
    Excel 2010
    Posts
    103

    Re: Hide non ajacent colums with a Macro

    Glad to be of service

    Dont forget to mark the thread as SOLVED

+ 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