+ Reply to Thread
Results 1 to 12 of 12

VBA code in HIDING & UNHIDING row if value is zero

  1. #1
    Registered User
    Join Date
    09-10-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    69

    VBA code in HIDING & UNHIDING row if value is zero

    I found a VBA code in hiding & unhiding row in the internet, but my problem is when I re-coding it so that it will suit for my needs it wont work.

    Please Help me!
    Thank you!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-10-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: VBA code in HIDING & UNHIDING row if value is zero

    if G14=4 then dp5 & dp6 value under column D will become zero, which is a no problem to be coz my excel formulae is ok. My problem is I cant hide the rows when column D value is zero.

  3. #3
    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: VBA code in HIDING & UNHIDING row if value is zero

    Hi, [email protected],

    your description seems to differ from the file you posted (there are no formulas in there). If there´s a formula displaying 0 the line will be hidden.

    For unhiding you should simplify the code to
    Please Login or Register  to view this content.
    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

  4. #4
    Registered User
    Join Date
    09-10-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: VBA code in HIDING & UNHIDING row if value is zero

    HI HaHoBe!

    What I mean was, in my actual Excel file, my formula is: IF(AND(G14=4,G15=3,G17=2) then the value of D28:D29, D36:D38 & D43:D46 is zero. Sorry for my sample attach file is wrong.

    When I manually put a zero value in any of this cell(D28:D29, D36:D38 & D43:D46), it does not "automatically" hides row. So that is my problem.

    Please Help me!

  5. #5
    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: VBA code in HIDING & UNHIDING row if value is zero

    Hi, [email protected],

    both the formula
    Please Login or Register  to view this content.
    in D28 as well as 0 in D29 lead to these rows being hidden by the code - at least in my file.

    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    09-10-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: VBA code in HIDING & UNHIDING row if value is zero

    Actually the code is working good, it hides & unhides rows....but NOT automatically.

  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: VBA code in HIDING & UNHIDING row if value is zero

    Hi, [email protected],

    maybe place that in the opening post as still the event on which the code should start working is not mentioned (for example Workbook_Open, Worksheet_Activate, Worksheet_Change, Worksheet_BeforeDoubleClick).

    Ciao,
    Holger

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA code in HIDING & UNHIDING row if value is zero

    This code is very slow.

    The Unhide code shoul be:-

    Please Login or Register  to view this content.
    I will look at the hide code in a bit.

    I assume that you want the macro to run whenever the sheet is calculated.

    BRB

  9. #9
    Registered User
    Join Date
    09-10-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: VBA code in HIDING & UNHIDING row if value is zero

    Hi Mehmetcik!
    Yes your right! In my Excel formula it needs to determine the "terms" then calculate the amount then it will appear in column D. After calculation then the hiding & unhiding of rows with the value of zero in column D will take place. As I said earlier, "the code is working good, it hides & unhides rows....but NOT automatically."

    At present I just create a button that I will click to start the hiding & unhiding process.

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA code in HIDING & UNHIDING row if value is zero

    Move your code to the sheet specific area for now.

    Right Click on the sheet name at the bottom of excel and select view code.

    Select worksheet on the left tab

    select change on the right tab.

    place your code inside the macro that is shown

    Your macro will now run whenever the sheet is changed.

    I will look at speeding it up for you.

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA code in HIDING & UNHIDING row if value is zero

    This is not as fast as I would like

    but a lot faster than you version.

    S

    Enjoy.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    09-10-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: VBA code in HIDING & UNHIDING row if value is zero

    Hi mehmetcik!

    rows 1-24 should not be hide no matter what the values are, only rows 25-438 will be moving.

+ 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