+ Reply to Thread
Results 1 to 27 of 27

VBA code for hiding column

  1. #1
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    VBA code for hiding column

    I need help here with VBA.

    I want to hide the row of player on the ATP Stats worksheet that have 0's in all competition, the file example can be download in next link.

    http://www.excelforum.com/2033721-post1.html

    Thanks.
    Last edited by MbahGondrong; 01-31-2009 at 10:24 AM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    I assume it's for the sheet named "ATP Stats"

    Try
    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    01-17-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: VBA code for hiding column

    heres an example of how to hide rows where a range of columns values are 0

    Please Login or Register  to view this content.
    Last edited by .paul.; 01-28-2009 at 04:16 PM.

  4. #4
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    @VBA Noob
    Yes It is for the ATP Stats worksheet.

    Alright, I never use VBA so I don't know how to use the codes. Can you explain where to put the codes and in what worksheet I should put it.

    Thanks.

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    Press Alt + F11 > insert module > paste in the code. Close VB editor > Press Alt + F8 > select HideZeros and run

    VBA Noob

  6. #6
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    Thanks a lot it worked great, but the number seems to be not in order, can that be in an order (1,2,3,etc)?

    Also how can I stop the module to run?

    Thanks.

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    but the number seems to be not in order, can that be in an order (1,2,3,etc)?
    Not what you asked. You would need to sort the data

    Also how can I stop the module to run?
    Don't understand the question

    VBA Noob

  8. #8
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    I mean making the table look like before the module is run. Yes I know it's different question, and the previous problem is done but the look is not good after that, I mean after 1 it's 4 and not in order.

    It is can be doned so that after the module run the number will still in order?

    Maybe this is new question so do I need open new thread?

    Thanks.

  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    Don't understand. Maybe a example

    VBA Noob

  10. #10
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    Alright this is the problem, I already apply your code in my original excel and run the macro. After that the data in ATP stats worksheet don't have the number in order. This can be seen in the attachment file in this post, you can compare it with the original attachment from the first post. I just want after the module is run the number in worksheet ATP Stats in order.

    Also after your module is applied anytime there is a row that is hidden have a point (1) it is not showed but still hidden.

    Thanks.
    Attached Files Attached Files
    Last edited by MbahGondrong; 01-29-2009 at 12:10 PM.

  11. #11
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    This should help with changing data.

    Code goes in sheet "ATP Stats". Right click sheet tab > select view code > paste in the below

    Please Login or Register  to view this content.
    VBA Noob

  12. #12
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    There seems to be nothing changing about the code and also there is some error about running the macro, it say about unsigned macro something.

    This is the case, you can see in the ATP 2009 worksheet there is data about winner of tournament, and data from the ATP Stats is from there. Now everytime a new winner is added in a tournament in ATP 2009, his name in the ATP Stats is not seen but still hidden.

    I hope that is informative enough.

    Thanks.

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA code for hiding column

    Before opening the workbook, do Tools > Macro > Security, and set to Medium.

    Then open the workbook and enable macros when prompted.
    Entia non sunt multiplicanda sine necessitate

  14. #14
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    Already done that but still the same.

  15. #15
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    Did you put the code in the worksheet.

    Here's my example

    VBA Noob
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    Thank you man that's what I mean for the add of players that just won tournament, but one more thing is as you can see that the number's in the left of players name is not in order. Anyway to fix that so it become in order?

    Also if I want to use the code in other worksheet is there anything I have to change or I just copy it?

    Thanks.
    Last edited by MbahGondrong; 01-30-2009 at 10:43 AM.

  17. #17
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    Will take a look after work but can you upload a example or the order you're after (Before and after sheet would be good)

    VBA Noob

  18. #18
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    This is the case.

    Before:
    \1

    After:
    \1

    See what is needed? and it should also apply when new data is shown (hidden become active) the data should follow in number order too.

    Thanks.

  19. #19
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    Seems to work. Code needs to go in "ThisWorkbook" Module and not the sheet module as before.

    Added the other sheet names at this line

    Please Login or Register  to view this content.
    e.g
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    VBA Noob

  20. #20
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    Alright so I need to make new module in VBA and paste all the code and run it again right?

  21. #21
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    Yes. New code goes in ThisWorkbook module (see link)

    http://www.contextures.com/xlvba01.html#Workbook

    VBA Noob

  22. #22
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    Do I still need the previous code?

    Thanks.
    Last edited by MbahGondrong; 01-31-2009 at 06:14 AM.

  23. #23
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    No.

    As i said

    Code needs to go in "ThisWorkbook" Module and not the sheet module as before.
    By placing in Workbook module it will work on all sheets instead of activate sheet which you asked for
    Please Login or Register  to view this content.
    Then add the sheets names you want to run the code on as I suggested

    PS. Best way to learn is to try so practice on a copy of the file first

    VBA Noob

  24. #24
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    Yes, that should do it thanks again. But there is some error I see, first everytime I delete all the winner and finalist from ATP 2009 worksheet the excel goes ino a freeze in the previous code it's alright if I delete all winner and finalist it won't freeze. And when new data added to ATP Stats from Source (data after row 46), it don't get affected by the macro.

    Second if the data that have been added is the last player in the list (Victor Hanescu) a number will appear outside the table in the ATP Stats worksheet. Can you look into that if you don't mind?

    Also this is kinda stupid question, in the ATP Stats for a column that have 0 point is not visible right but when I copy it to other sheet the 0 appear and I forgot how I can make 0's not visible, can you help me into his also?

    Thanks.
    Last edited by MbahGondrong; 01-31-2009 at 08:35 AM.

  25. #25
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    Sorry not going to go off course any more did more than your first post as for now

    This help is free and we give it not to do you're project but for a specfic problem you have. At this rate I will be wasting so much time on this and not helping others

    VBA Noob

  26. #26
    Registered User
    Join Date
    01-23-2009
    Location
    Bandung, Indonesia
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: VBA code for hiding column

    No problem anyway thanks for all the help you give me, I think I'll just try to understand your code now. Do you have any good VBA E-book for newbie that you recommend? I don't understand a thing about your code there.

    Thanks.

  27. #27
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA code for hiding column

    Recording you're actions is a good way to learn and reading posts on the forum.

    I would suggest Walkenbach's books.

    If you want someone to finish the project and willing to pay you can post in the Commercial Services Exchange .


    VBA Noob

+ 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