开发者

Is it possible to have a "reset form" button in an excel form?

Is there a way to make a reset button in an Excel Spreadsheet form? That is I'd like to make it easy clear all the entered data, but not any of the formulas.

EDIT: Further explanation: Really it's just a spreadsheet. When we count the money each morning we have a form where we write down every different denomination of money, and then add it all up (by then putting those numbers into a开发者_如何转开发 calculator). I figure it would save time and reduce errors if we just typed the totals into a spreadsheet and let Excel do the math for us. However several folks aren't very technically literate, so I'd like to ensure that the formulas aren't accidentally deleted.


There is no generic "reset button", so you have to make one yourself.

Add a button to your sheet, and edit its code in the sheet module:

Private Sub CommandButton1_Click()
    ClearInput
End Sub

In a (regular code) module, make a Sub that does what you want:

Sub ClearInput()

    Dim rngInput As Range
    Set rngInput = Sheet1.Range("B1:C4") ' Or wherever the user input goes
    rngInput.ClearContents

End Sub

A more flexible solution is to have in your sheet a named range (called e.g. "UserInput") that covers all the cells that will need clearing later on. Then you can replace the Set statement in the code above with Set rngInput = Sheet1.Range("UserInput").


Following on your comment "However several folks aren't very technically literate, so I'd like to ensure that the formulas aren't accidentally deleted." (which you may want to migrate to the question):

If what you want is make sure that users don't accidentally input data in other cells than they need to, you'll want to protect the sheet and just unprotect the input cells (cells are portected by default). When protecting the sheet, allow "Select Unlocked Cells" but disable "Select Locked Cells". If you're just trying to fight accidents and not malice altogether, I probably don't need a password, but that's an option too.

One added bonus of doing this is that is only the input cells are selectable, one can just tab between them to input data, wherever they are.


You can use VBA to do this. Without seeing your spreadsheet I can't give you any specifics, but you can do this to set all Cells in Column A rows 1-15 to an empty string.

ActiveSheet.Range("A1", "A15").Value = ""
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜