+ Reply to Thread
Results 1 to 26 of 26

hiding columns based on certain criteria

  1. #1
    Registered User
    Join Date
    07-11-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    24

    hiding columns based on certain criteria

    Hello!
    I have a problem that I'm trying to solve. I have a sheet full of data, with headers on row 5 and some cells here and there left empty. All headers are filled in, but there are some prices that have not been agreed upon which are then left empty. I'm using a filter on the headers, and with some filtering conditions whole columns can be left empty. What I want to do then is write a script that hides all empty columns (similarly to a normal, manual filter). However, since the column will have a value in the header row and a number of hidden values due to the filter the statement

    Please Login or Register  to view this content.
    will not work. My question then is, is it possible to add exceptions for the header and the hidden data to this statement (and to If statements in general)? Otherwise, can you see any other way of accomplishing this without having to scroll through all of the data, because that would be rather time-consuming?

    Regards,
    Samuel

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: hiding columns based on certain criteria

    How about this, change the range you want to use.

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Registered User
    Join Date
    07-11-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: hiding columns based on certain criteria

    Hi Dave,
    I've tried your script with some small modifications, but it doesn't seem to do anything. Here's the code:

    Please Login or Register  to view this content.
    I'm guessing that it doesn't make exceptions for hidden values when it scans a column, reading up on the Find Method right now.

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: hiding columns based on certain criteria

    Those small modifications unfortunately make the code not work. It is not the find part that is the problem.

    This line won't hide columns, so change this.
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-11-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: hiding columns based on certain criteria

    Well, I actually tried running it as written before I started changing anything. :p

    And still doesn't do anything :O

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: hiding columns based on certain criteria

    Best post a workbook. The code is sound.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: hiding columns based on certain criteria

    Hi, Solaris,

    maybe try it like this (adapt the row number for the headers of the table to the last seen number of rows for it, here the header is only in the first row):
    Please Login or Register  to view this content.
    @Dave:
    from what I understood you would have to get the header row out of the area to check.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  8. #8
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: hiding columns based on certain criteria

    My bad. Didn't even think about headers.

  9. #9
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: hiding columns based on certain criteria

    Please Login or Register  to view this content.

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: hiding columns based on certain criteria

    Please Login or Register  to view this content.



  11. #11
    Registered User
    Join Date
    07-11-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: hiding columns based on certain criteria

    Perfect, it works like a charm now! Thank you all for helping me out =)

  12. #12
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: hiding columns based on certain criteria

    Quote Originally Posted by snb View Post
    Please Login or Register  to view this content.
    Bada$$!

    Now why didn't I think of that.

  13. #13
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: hiding columns based on certain criteria

    @JapanDave

    Please start your own thread if you have a question

  14. #14
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: hiding columns based on certain criteria

    LOL. You will have to help me with the title as I don't know how to word it correctly for it to potentially show up in a Google search!

  15. #15
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: hiding columns based on certain criteria

    @JapanDave

    Probably: which brain surgeon can implant the VBA library into my striate cortex ?

  16. #16
    Registered User
    Join Date
    07-11-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: hiding columns based on certain criteria

    Name it "Why didn't I think of that?".

    You're welcome. Now give me reputation plz!



    Edit: Or the above. That also works.

  17. #17
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: hiding columns based on certain criteria

    What reputation ? which reputation ?

  18. #18
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: hiding columns based on certain criteria

    So snb, where did you get your implant? LOL I need a referral.

  19. #19
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: hiding columns based on certain criteria

    Some obscure Japanese Zen mental health clinic...
    I will send a recommendation so you will get a bargain.

  20. #20
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: hiding columns based on certain criteria

    Hi, snb,

    as long as there´s only one column holding the blanks: congrats. As I had some blanks in the other columns as well I got a result from the code which wasn´t what OP had asked for (maybe I shouldn´t be so lazy as not to fill out whole areas except for one column ).

    Ciao,
    Holger

  21. #21
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: hiding columns based on certain criteria

    @Hahobe

    I tested with 3 columns holding any blanks. No problem.

  22. #22
    Registered User
    Join Date
    07-11-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: hiding columns based on certain criteria

    @HaHoBe, I am in fact using your solution. My post just happened to land after snb:s.

    @snb, When I try your version my whole sheet gets hidden. I have blanks mixed in in all columns, but I only want to hide columns that are all blank.

  23. #23
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: hiding columns based on certain criteria

    So why didn't you post a sample workbook ?

  24. #24
    Registered User
    Join Date
    07-11-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: hiding columns based on certain criteria

    Because the data I'm working with is confidential and property of a large company, and even though I'm sure there would be no harm I will follow company regulations and not post any data. Secondly, when I was in the process of creating a dummy sheet to post here HaHoBe gave me a working solution, so I used it and went back to work instead of continuing. I posted immediately when I had the solution, but since I didn't refresh the page before posting I didn't see your post until after. Hope that clears it up.

    Regards,
    Samuel

  25. #25
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: hiding columns based on certain criteria

    I asked for a sample workbook (see the forum fules), not your workbook.

  26. #26
    Registered User
    Join Date
    07-11-2012
    Location
    Sweden
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: hiding columns based on certain criteria

    Yes, and I was working on one as per JapanDave's request when HaHoBe posted a working solution. So I scrapped the sample, since it wasn't relevant anymore.The rules don't say anything about having to post a sample workbook after a thread has been resolved, but suggest it in order to get a faster response. It was a good thing I read them though, now I know how to change the status of the thread.

    If you feel offended by anything I've written I apologize, though I have a hard time seeing why you would. I will change the status of this thread to solved.

    Thank you all for your input!

    Regards,
    Samuel

+ 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