+ Reply to Thread
Results 1 to 10 of 10

Hide checkbox when formula returns ""

  1. #1
    Registered User
    Join Date
    10-04-2013
    Location
    Liverpool
    MS-Off Ver
    Excel 2003
    Posts
    27

    Hide checkbox when formula returns ""

    I have sheet made of values returned by formulae and a cheeckbox per row to be able to select which rows the user wants to use.

    I want to be able to hide the checkboxes when the formula for that row returns "".

    The event needs to run everytime the sheet recalculates, there is no manual entry on that sheet.

    I've tried things similar to below but i'm not sure i'm even close.

    Please Login or Register  to view this content.
    If anyone can give some pointers i'd be very grateful for the assistance.

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Hide checkbox when formula returns ""

    Try

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Hide checkbox when formula returns ""

    Hi ungers,

    You are very close and very far away at the same time.
    a. The Value of cell 'C36' is probably 0, even if BLANK is displayed. To get around this you probably have to test the Text value of the cell and remove leading and trailing spaces with the Trim() function.
    Please Login or Register  to view this content.
    b. The remainder of your code works, but is going to get out of hand due to repetition with several CheckBoxes. You probably need a naming convention for your CheckBoxes to be able to do your testing in a loop. I like to use names like 'Check Box F13' to indicate a Forms CheckBox (Forms CheckBoxes are created with spaces in the name) located in cell 'F13'. Using a naming convention like that, you can use the following routines (tested and working) during software development to create and delete your CheckBoxes. Additional macros are included to trap CheckBox events and to display or hide the CheckBox per your original question.

    In an ordinary Code Module:
    Please Login or Register  to view this content.
    In the Sheet module include the following code:
    Please Login or Register  to view this content.
    Lewis

  4. #4
    Registered User
    Join Date
    10-04-2013
    Location
    Liverpool
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Hide checkbox when formula returns ""

    I've made progress with the following only my loop only seems works on the first row?

    Please Login or Register  to view this content.
    I assume a silly mistake somewhere but i can't find it!

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Hide checkbox when formula returns ""

    Hi,

    Your code indicates that your CheckBox names start at "Check Box 101" and you start in cell 'B4'.

    Your main problem was that the line in red has to be inside the loop.
    It is also possible that your value test would always indicate false.

    Try this.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-04-2013
    Location
    Liverpool
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Hide checkbox when formula returns ""

    That's great thank you. As soon as I moved that line inside the loop it worked fine.

    A further thing though I have a select all checkbox, but I think because I have used Sub Worksheet_Calculate() above it takes ages to work as I think it is recalculating everytime a checkbox is changed.

    Is there anyway I can refine when the code runs or temporarily disable it with the select all macro?
    Last edited by ungers; 03-17-2015 at 06:40 PM.

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Hide checkbox when formula returns ""

    It probably is recalculating. The following changes in red should improve speed performance:
    Please Login or Register  to view this content.
    Lewis

  8. #8
    Registered User
    Join Date
    10-04-2013
    Location
    Liverpool
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Hide checkbox when formula returns ""

    I just moved this code to the sheet (called "results") where all the selections are made as the sheet "bank summary" is really just a display.

    I also added in the following 2 lines to reset all the checkboxes when the underlying data is changed or the user makes a different selection.

    Please Login or Register  to view this content.
    This works fine but now whenever I try to check a box it is also triggering the results sheet worksheet calculate event and therefore resetting them to false again. If I comment out these two lines it works fine. There is no connection between these sheets.

    So why is an action on one sheet triggering the event on the other?

  9. #9
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Hide checkbox when formula returns ""

    I think there are probably 2 problems:

    a. In the Sheet module for the "BANK SUMMARY" Sheet the code works, but should be (changes in red):
    Please Login or Register  to view this content.
    b. You probably copied the sheet, and there is Worksheet_Calculate() code for the sheet. Worksheet_Calculate() should probably be deleted on the new sheet. The Worksheet_Calculate() on the new sheet as it currently exists, probably references sheet "BANK SUMMARY" and is probably the reason for the problems.

    Lewis

  10. #10
    Registered User
    Join Date
    10-04-2013
    Location
    Liverpool
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Hide checkbox when formula returns ""

    I made a mistake and there is a two way relationship between the two sheets so that's why it was re-calculating.

    I got round this by making a new sheet with a single cell based on the radio button selection and used Worksheet_Calculate() and moved the follfowing there to reset the sheet.

    Please Login or Register  to view this content.
    Thanks for all you assistance.

+ 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. Replies: 3
    Last Post: 04-16-2014, 10:00 AM
  2. Replies: 1
    Last Post: 09-21-2013, 03:18 AM
  3. [SOLVED] if formula returns ":false" instead of "0"
    By pja_14 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-20-2013, 04:09 AM
  4. Hide entire row where formula returns "" or blank value
    By zcheema in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-24-2012, 05:26 PM
  5. Replies: 4
    Last Post: 12-26-2011, 05:09 PM

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