+ Reply to Thread
Results 1 to 16 of 16

Execute code based on cell entry

  1. #1
    Forum Contributor rkjudy's Avatar
    Join Date
    03-31-2009
    Location
    Longview, TX
    MS-Off Ver
    MS Office 2010
    Posts
    239

    Execute code based on cell entry

    I would like to write the code or create a macro that will execute when the value of a range of cells is greater than null. The macro or code that I would like to execute will UNHIDE a group of consecutive rows. Any suggestions?
    Last edited by rkjudy; 10-29-2009 at 01:28 PM. Reason: Further explain my question.

  2. #2
    Registered User
    Join Date
    10-11-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    59

    Re: Execute code based on cell entry

    Hi,

    This can be easily done using the worksheet change event. However, more information would be needed to proceed. Below is a sample code from Microsft MVP Smitty. It is relevant for changes to column B.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor rkjudy's Avatar
    Join Date
    03-31-2009
    Location
    Longview, TX
    MS-Off Ver
    MS Office 2010
    Posts
    239

    Re: Execute code based on cell entry

    Please see attached sheet. Hopefully this will help. As you can see, rows 14-25 are hidden. If there is any numeric entry >0 in cell C11, C12, or C13, I want to UNHIDE rows 14-25. I would also like to reHIDE the cells if the value in any of the 'C' cells above are returned to null.
    Attached Files Attached Files
    Last edited by rkjudy; 10-28-2009 at 10:52 PM.

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

    Re: Execute code based on cell entry

    Maybe like this. Code goes in the Build Quote sheet module.
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Contributor rkjudy's Avatar
    Join Date
    03-31-2009
    Location
    Longview, TX
    MS-Off Ver
    MS Office 2010
    Posts
    239

    Re: Execute code based on cell entry

    Wow, it worked perfect. Along those same lines, is it possible to UNHIDE the rows in question just by clicking on any of the 'C' cells, and then hide again if I click off to any other cell?

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

    Re: Execute code based on cell entry

    You need to flesh out the logical behavior. What's the intended interaction of that with the other code?

  7. #7
    Forum Contributor rkjudy's Avatar
    Join Date
    03-31-2009
    Location
    Longview, TX
    MS-Off Ver
    MS Office 2010
    Posts
    239

    Re: Execute code based on cell entry

    Not sure what you're asking, but instead of having to make a positive entry in one of the 'C' cells to execute the UNHIDE, I would like for the UNHIDE to occur just by focusing (clicking) on one of the 'C' cells.

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

    Re: Execute code based on cell entry

    Replace the other code with this:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor rkjudy's Avatar
    Join Date
    03-31-2009
    Location
    Longview, TX
    MS-Off Ver
    MS Office 2010
    Posts
    239

    Re: Execute code based on cell entry

    That didn't seem to work or do anything. Remember, rows 14-25 start out hidden when the workbook is opened. I really would just need the rows to be UNHIDDEN if I click on any of the 'C' cells. I don't really need the rows to return to HIDDEN if I click off the 'C' cells. It's OK if they stay UNHIDDEN.

    This is what I tried:

    Please Login or Register  to view this content.

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

    Re: Execute code based on cell entry

    To reverse the logic, put the word Not before Intersect.

  11. #11
    Forum Contributor rkjudy's Avatar
    Join Date
    03-31-2009
    Location
    Longview, TX
    MS-Off Ver
    MS Office 2010
    Posts
    239

    Re: Execute code based on cell entry

    This is what I tried and it didn't work either. It seems I need an IF Statement. ie. IF any of the 'C' cells are selected (or get focus), UNHIDE rows 14-25.


    Please Login or Register  to view this content.
    Last edited by rkjudy; 10-29-2009 at 12:18 AM.

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

    Re: Execute code based on cell entry

    The code goes in the same sheet module where the other code was. If you select C11, C12, or C13, rows 14:25 hide; select any other cell, and they unhide (both referring to the version with the NOT). It does not require any IF.

  13. #13
    Forum Contributor rkjudy's Avatar
    Join Date
    03-31-2009
    Location
    Longview, TX
    MS-Off Ver
    MS Office 2010
    Posts
    239

    Re: Execute code based on cell entry

    Everything seems to work now, thanks. I do have one more adjustment I need help with. When the code you gave me executes (by clicking in one of the 'C' cells), it DOES, in fact UNHIDE rows 14-25. But, if I click off one of the 'C' cells, rows 14-25 go HIDDEN again. Once they are UNHIDDEN by clicking on a 'C' cell, I'd like for them to stay UNHIDDEN. Can I make a change to keep them UNHIDDEN if I click off a 'C' cell and click to, for instance D45? Here's my code now:

    Please Login or Register  to view this content.
    Thanks again for your patience.

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

    Re: Execute code based on cell entry

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor rkjudy's Avatar
    Join Date
    03-31-2009
    Location
    Longview, TX
    MS-Off Ver
    MS Office 2010
    Posts
    239

    Re: Execute code based on cell entry

    Works perfect. Thanks for everything.

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

    Re: Execute code based on cell entry

    You're welcome. Would you please mark the thread as Solved?

+ 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