+ Reply to Thread
Results 1 to 11 of 11

Need Help with Hide/Unhide Rows Based on Zero Value in Column

  1. #1
    Registered User
    Join Date
    10-30-2019
    Location
    Birmingham, AL
    MS-Off Ver
    2016
    Posts
    6

    Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Hi All-
    I have spent hours trying to find the right code to do what I need and can't seem to find exactly what I need.

    I have an excel workbook with several different sheets. I need a code for the sheet named "Budgeted Expense Statement" that works when a cell value in Column O is zero, the row is hidden. The range is A2:Q970)

    I have found many codes that do that part and work just fine. However, the values in column O are based off formulas that are tied to others sheets/cells (the values are not manually entered into these cells), and so when I update values elsewhere in the workbook/sheets, it updates the values in column O and the value is no longer zero, but the rows remain hidden.

    I need a code that will hide the rows if the cell value in Column O for that row is zero, but then update and unhide when the values in those cells are updated and are no longer zero. This is a workbook that I will update monthly, so I can't just run it once and be done, it needs to be done automatically every time that cell either equals zero or doesn't equal zero any longer.

    I found one code (it has been days ago and I don't have it anymore) that worked, but the macro constantly ran and I couldn't type anything anywhere in the workbook because it was constantly checking if the values were zero.

    I could also just filter the spreadsheet every month after I am done, but other people will be accessing this workbook and I need it to be an automatic thing because I am not sure they would understand how to even filter things to see the information they need to see.

    I'd be ok with a code that I could add to a button that would update by clicking a button if that is what it needs to be.

    I've tried to upload an example of just the sheet I am needing to update, but understand that the actual workbook I am using has 4-5 sheets in the workbook that the information all feeds back to a sheet much like the example sheet (but much, much larger).

    Thanks in advance for your help!
    Attached Files Attached Files
    Last edited by amyly2n; 10-31-2019 at 03:04 PM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Hi there,

    It's not possible for me to test this properly because the links which cannot be resolved calculate as #VALUE errors, but see if the following code, inserted into the VBA CodeModule of the worksheet in question, gets you moving in the right direction:

    Please Login or Register  to view this content.
    The highlighted value may be altered to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    10-30-2019
    Location
    Birmingham, AL
    MS-Off Ver
    2016
    Posts
    6

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Thank you for your answer and help!

    It appeared to be working as soon as I hit F5, but then it freezes my workbook and I can't really tell if it fully worked or if it will work once the fields that had zero in them previously are updated to a number greater (or less than) zero. I guess freezes isn't the correct word, the VBA Code Module says "running" while the Excel spreadsheet just flickers and in the bottom left corner it alternates between "Ready" and "Calculate".

    What I can see of the spreadsheet looks like it was working, but I don't really know since I can't get to the final spreadsheet and then update it and see if it works.

    I just left it running in the background for 20 minutes and it never finished. I will just keep it up and running in the background and see if it finishes soon.

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Hi again,

    Many thanks for your feedback.

    Sorry, I got caught out by one of Excel's little "funnies" - it seems that hiding/unhiding a row containing cells which are used in a formula actually triggers the "Worksheet_Calculate" event, so this routine was being called many times more than it should have been!

    See if the following code does a better job:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.


    Hope this helps - as before, please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-30-2019
    Location
    Birmingham, AL
    MS-Off Ver
    2016
    Posts
    6

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Greg-
    Thanks again.

    When I input that, it says "Compile Error: Syntax error"

    The first line is highlighted yellow (it won't highlight below) and the following two lines text changed to red. I did notice that it put asterisks in front of the 2 and on either side of the zero after I hit F5 and that wasn't in you text above, if I remove those and try again, that give me a whole different error.

    Private Sub Worksheet_Calculate()

    Const iFIRST_DATA_ROW As Integer = *2
    * Const sTOTALS_COLUMN As String = "*O*"

  6. #6
    Registered User
    Join Date
    10-30-2019
    Location
    Birmingham, AL
    MS-Off Ver
    2016
    Posts
    6

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    I am working on setting up a sample sheet that will have formulas that update from a separate sheet much like my real life workbook will, maybe that will help.

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Hi again,

    Thanks for your very prompt feedback.

    Ok, there's definitely something very strange about those asterisks appearing!

    Just as a check on whether or not we're going in the right direction - in the workbook I posted, change the value of Cell C3 from 20 to e.g. 21 and see what happens. You should see a lot of #VALUE errors appear, but the rows which have zero values in Column O should be hidden.

    Just trying to visualise what's happening at your end - does the compiler error message say something like "Invalid use of Me keyword"? If so, it suggests that you're inserting the code in a standard VBA CodeModule rather than in the CodeModule for the worksheet itself.

    Please keep me posted.

    Regards,

    Greg M
    Last edited by Greg M; 10-31-2019 at 09:35 PM. Reason: Typo corrected

  8. #8
    Registered User
    Join Date
    10-30-2019
    Location
    Birmingham, AL
    MS-Off Ver
    2016
    Posts
    6

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Ok, attached is a working miniature version of the workbook (including formulas and additional sheets) that I am trying to make work by hiding cells that equal zero in the FY Total Column (or Column O) on the Budgeted Expense Statement sheet.

    As you can see, the cells from C3:N18 in the Budgeted Expense Statement sheet are all driven by formulas based off items on the Itemized Expense sheet satisfying certain "IF" statements (basically if the object code and period name on the Itemized Expenses sheet match Column A and the column headings for C:N respectively, it will add the items together and insert them in the appropriate cell) and the FY Total Column cells is the sum per row of the columns C:N.

    So, this workbook is updated monthly with new entries on the Itemized Expense sheet and the Budgeted Expense Statement sheet has 970 rows, so ideally the rows would hide/unhide as the FY total column cell values are greater or less than zero as new entries are made monthly. I really don't want to scroll through 970 rows, but they need to be there just in case there is an entry throughout the year.

    If the code works to hide the rows correctly initially (like so many previous codes I have tried do), I need it to work to unhide rows that were previously hidden when adding entries on the Itemized Expenses sheet causes the FY Total column on the Budgeted Expense Statement sheet to no longer equal zero.

    If you want to test if it works when updated, you can update any of the values in Column I (Check Amount) on the Itemized Expenses sheet that currently equal zero and it should make the FY Total Column (and other cells) update on the Budgeted Expense Statement sheet and hopefully unhide.

    Edited to add: If you want to try it, update any of the Zeros that say "Laverne" in the Payee Column on the Itemized Expenses Sheet. I know that one will for sure make the FY Total Cell Value change and no longer be zero.
    Attached Files Attached Files
    Last edited by amyly2n; 10-31-2019 at 11:32 AM.

  9. #9
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Hi again,

    Many thanks for that detailed explanation.

    Ok, let's see if we've got it nailed this time!

    I've inserted my previous code in your latest workbook and it seems to do the trick. To see this, just change the value in the highlighted cell on the "Itemized Expenses" worksheet and see Row 16 on the "Budgeted Expense Statement" worksheet appear/disappear as appropriate.


    Hope this helps - as always, please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    10-30-2019
    Location
    Birmingham, AL
    MS-Off Ver
    2016
    Posts
    6

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Greg! You are awesome!

    It worked perfectly and super fast too! In fact, it was so fast, I thought it hadn't worked at all! It made 970 rows condense down to 68 in the blink of an eye! And, then it made the new line appear so quick it again took me a second to realize it worked!

    I can't wait to put my worksheets into use for my new fiscal year!

    THANK YOU VERY VERY VERY MUCH!

  11. #11
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Need Help with Hide/Unhide Rows Based on Zero Value in Column

    Hi again,

    Many thanks for your very prompt feedback - looks like we got there in the end!

    You're welcome - glad I was able to help.

    Best regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to unhide & hide rows based on column value
    By qvfr034 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-15-2020, 03:00 PM
  2. Automatically hide/unhide rows based on column A value
    By c.bernardo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-14-2017, 12:30 AM
  3. Hide/Unhide Rows based on column data using checkbox
    By ricklberry in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2015, 11:39 AM
  4. [SOLVED] VBA macro that hide and unhide column to respective rows based on first column value
    By janine6192 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2013, 06:21 PM
  5. Auto Hide/Unhide rows in Excel based on formula result in a column
    By crozierk in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-12-2012, 08:02 AM
  6. Macro to Hide/Unhide Rows Based on Results in Column Equation
    By jwhite0720 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2011, 04:59 PM
  7. Hide/Unhide Rows based on Zero Value
    By chiz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-09-2010, 05:28 AM

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