+ Reply to Thread
Results 1 to 11 of 11

Create a clear/reset "button"?

  1. #1
    Registered User
    Join Date
    12-16-2008
    Location
    Minneapolis
    Posts
    16

    Create a clear/reset "button"?

    Geniuses-

    I'm just finishing a project that is a collection of three calculators, each of which returns data based on a series of user-supplied variables. All the mechanics are working [thanks in part to replies to previous posts], but there is one more thing I'd like to add:

    Does anyone have a way to clear the contents of another cell [actually several] cells via another cell? As the most complex calculator requires eight variables to be entered, I'd like to provide a quick way [a button?] to "clear" or "reset" the calculator - basically wipe all unlocked cells. I should note that all of the cells in question already have Data Validation of one type or another.

    Any assistance will be generously rewarded with kind thoughts.
    Thanks in advance,
    joe in MPLS
    Last edited by splenguin; 09-03-2009 at 04:26 PM.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Create a clear/reset "button"?

    Does anyone have a way to clear the contents of another cell [actually several] cells via another cell?
    What is the condition/value in "another cell" that should trigger a reset of the input cells?
    What are the sheet/range references for the input cells to be cleared?

    Upload a sample workbook if you can.

  3. #3
    Registered User
    Join Date
    12-16-2008
    Location
    Minneapolis
    Posts
    16

    Re: Create a clear/reset "button"?

    The condition/value of the "clear variables" cell is what I could use some suggestions on. I don't suppose it would be possible to create a cell that needs only be clicked [hyperlink?] to clear the other cells.

    As far as the cells that need to be cleared, I have two types of Data Validation, which I have recreated in the attached example. The first is a simple drop-down list [Animals], and the second [Decimal] allows a decimal to be entered, but ONLY if an animal has not been selected.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Create a clear/reset "button"?

    Right-click the sheet tab
    Select View Code
    In the window that comes up paste this:
    Please Login or Register  to view this content.
    Substitute B2 etc. for your ranges. You can add more, I'm sure you'll be able to piece it together.
    Close that window (the whole VBA editor)
    Right-click a toolbar (to get a list of available toolbars)
    Get the "Forms" toolbar
    Click the button icon
    Draw a button on your sheet, it should ask you for a macro, pick ClearCells
    profit

    HTH

  5. #5
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Create a clear/reset "button"?

    see the example.
    use some variation of code given by Cheeky Charlie.
    modytrane
    Attached Files Attached Files

  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: Create a clear/reset "button"?

    Select all the cells you want to clear, and in the Names box, left of the Formula Bar, give them a name, e.g., 'Sheet1'!rgnInp, replacing Sheet1 with the actual name of the sheet

    Then in code,
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Create a clear/reset "button"?

    I'm just finishing a project that is a collection of three calculators, each of which returns data based on a series of user-supplied variables.
    I don't see how the example workbook you provided does any type of calculating.

    Although several good suggestion/examples have been put forth, you could get an answer tailored to your specific situation if you provide a workbook that is truly reflective of what you describe above - a collection of calculators.

  8. #8
    Registered User
    Join Date
    12-16-2008
    Location
    Minneapolis
    Posts
    16

    Re: Create a clear/reset "button"?

    Thanks all for the replies - I'm very close to the solution. I went with the code suggested by cheeky and shg, though it seems the problem is that one of the fields I'm trying to clear is actually three cells merged and centered. When I run the macro from the worksheet, it returns an error that only reads "400", so I tried running it from the VBA Editor, and it errors: Cannot change part of a merged cell." Is it generally bad practice to use merged cells? I merged them to take advantage of available space in the "UI" and would prefer not to un-merge them... any bright ideas?

  9. #9
    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: Create a clear/reset "button"?

    Is it generally bad practice to use merged cells?
    It is uniformly terrible practice to use merged cells if the contents are used for anything other than presentation -- i.e., if there is any downstream dependency.

  10. #10
    Registered User
    Join Date
    12-16-2008
    Location
    Minneapolis
    Posts
    16

    Re: Create a clear/reset "button"?

    I've unmerged the cells, and the script is working perfectly. Thank you all-

  11. #11
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Create a clear/reset "button"?

    It is uniformly terrible practice to use merged cells
    :D

    I agree 100%, though I've never managed quite the pithy flourish of this remark in any of my anti-merged-cells rants

    If your merged cells were on the same row, you can use "centre across selection" alignment to achieve a merged-and-centred effect (select cells, Ctrl+1, CAS is the last horizontal alignment setting in the list)

    CC

+ 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