+ Reply to Thread
Results 1 to 6 of 6

Hide specific rows with macros

  1. #1
    Registered User
    Join Date
    12-10-2012
    Location
    Western Cape, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    4

    Hide specific rows with macros

    I am completely new to macros in excel. I have been searching on the internet and it seems that macros are the only way I can get what I want.
    I have the following problem:

    example excel.PNG

    Now in this picture, budget normally starts at zero for everything. When I filled in what needs to be filled in, I want a command that will allow me to do the following. Hide all the rows where budget = 0. If 2.2.1 till 2.2.7 are all 0 then the row with 2.2 also needs to hide. But if for example 2.2.4 is $50, then 2.2. has to remain. If 2.1 till 2.5 are all hidden, then the row with 2.0 needs to hide etc.

    If you see the image, after the macro it should look like the following:
    example excel 2.PNG

    As I said, I am completely new to the world of Macro's. I have googled quite some time now, but could not find an answer to my question... I believe it can be done quite simply but my attempts at writing a code all failed miserably, where I don't even know what went wrong or even if I did anything right...

    I hope someone can help me with this problem.

  2. #2
    Registered User
    Join Date
    12-10-2012
    Location
    Western Cape, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Hide specific rows with macros

    okay, I have written now the following code and it seems to be working:

    Public Sub Budget()
    If Range("K16, K19").Value = 0 Then
    Rows(15).Hidden = True
    Else
    Rows(15).Hidden = False
    End If
    End Sub

    But now, in reality this sheet is a LOT bigger, so it is quite some work to do this for all subjects... Is this the easiest way?

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

    Re: Hide specific rows with macros

    I think there is a way with the use of a macro, but I honestly think you should rearrange your spreadsheet. The thing you want could be easily done with a simple filter if your sheet looked like the workbook I attached.

    edit: It would be a lot more useful for future uses also. It is much easier to make graphs, pivot tables and sort data if your data looks like a database (no empty rows/columns/cells).
    Attached Files Attached Files
    Last edited by RHCPgergo; 12-10-2012 at 11:43 AM. Reason: spelling, additional info

  4. #4
    Registered User
    Join Date
    12-10-2012
    Location
    Western Cape, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Hide specific rows with macros

    Wow, a whole new world opens up for me. Never really knew what pivot tables were. Thank you, I think I can work with this. This is probably even better then my idea, at least a lot less complicated

  5. #5
    Registered User
    Join Date
    12-12-2012
    Location
    Lamar, Missouri, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Hide specific rows with macros

    In this code you placed below

    Public Sub Budget()
    If Range("K16, K19").Value = 0 Then
    Rows(15).Hidden = True
    Else
    Rows(15).Hidden = False
    End If
    End Sub

    What does the (15) represent, and if i wanted to use the same thing to check multiple values for being zero, how would i replace ("K16, K19") with multiple values, could I somehow use ("K16, K19" and "L16, L19" and "M16, M19"), and what would be the proper format for that. One last question when using that method why did you only use K16-K19 and not K16-K37?

  6. #6
    Registered User
    Join Date
    12-10-2012
    Location
    Western Cape, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Hide specific rows with macros

    The (15) represents row number 15. It means that if the Range K16 till K19 zero is, then row 15 must be hidden. If not, then not.

    I do not know the proper format for it, like I said, I'm also new to this.

    I did not make the range k16-k37 because I wanted it to go per subtitle. So the next code will be to hide row 20 with range K21-K27 etc.

    Lastly I opened the threat again for you so hopefully you will get a good reply.

+ 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