+ Reply to Thread
Results 1 to 5 of 5

Hide Columns not Matching Reference Cell?

  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    55

    Hide Columns not Matching Reference Cell?

    Hi all!

    Thanks for taking the time to read this. Needing the help of a Macro wizard!

    I'm a newbie at Macros but very keen to learn. I want to create a Macro to hide a set range of columns that do not contain a matching reference to cell (say A1).

    Cell A1 will contain a text reference which will vary and this will be referenced on the same row in each column (example attached).

    Could someone help me write this Macro, and if willing, explain the commands line by line (or anything else you think I should know!).

    I would be very grateful!!!

    Regards,

    Coeus.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Hide Columns not Matching Reference Cell?

    Something like this should do - I've put in comments, but feel free to ask if you have questions:

    To insert this macro:

    1. With your workbook open (and it will be easiest if you only have one workbook open) press Alt-F11 to open the VB editor
    2. In the panel on your left will a list of the sheets in your workbook - double click on the sheet that contains your data
    3. A blank text editor window will open
    4. In the left-hand drop-down above that window select "Workbook"
    5. In the right-hand drop-down select "Change"
    6. The first and last lines of the macro below will be automatically inserted, paste the rest of my code in between them
    7. Close the VB editor (red cross at the top right)
    8. You will no longer be able to save your workbook as a *.xlsx file, so save it as a *.xlsm (macro enabled workbook)
    9. Give it a whirl and let me know how it goes
    Please Login or Register  to view this content.

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Hide Columns not Matching Reference Cell?

    Heres another

    Please Login or Register  to view this content.
    Last edited by mike7952; 01-22-2013 at 03:19 PM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  4. #4
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Hide Columns not Matching Reference Cell?

    Here is a simple one for you. It could be more efficient (which would actually matter if you had a lot more columns), but it's good for explaining things. It should be run while the active sheet is the one you want to apply it to. Have fun learning!

    Also read John Walkenbach's book titled "VBA programming for dummies". It's amazing!
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-22-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: Hide Columns not Matching Reference Cell?

    Holy poo on a stick that Macro was amazing Andrew-R!

    Not only how it works but the time it took you to compile it outstands me. Easy 2 hours work and research for me to achieve this!

    I'm going to have to go through each line and probably Google it to be able to understand and replicate but it works perfectly!

    Many many thanks to you, Mike and Gergo.

    Is John Walkenbach's book titled "VBA programming for dummies" universally recommended?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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