vb清除单元格_清除单元格并留下公式

vb清除单元格

On most of the worksheets that I build, there is a mixture of labels, data entry cells, and cells with formulas. Here's how to clear cells and leave formulas, if you want to start a new entry.

在我构建的大多数工作表上,都有标签,数据输入单元和带有公式的单元的混合体。 如果要开始新的条目,请按以下步骤清除单元格并保留公式。

订单表格 (Order Form Worksheet)

For example, here is the worksheet from my Excel order form tutorial. The shaded cells are where you enter data, and the white cells have formulas or labels.

例如,这是我的Excel订单表单教程中的工作表。 阴影单元格是您输入数据的地方,白色单元格具有公式或标签。

clearconstants01

清除数据 (Clear Out the Data)

When it’s time to fill in a new order, what do you do? Ideally, you would have a blank template for this form, and open a new copy, each time that you wanted to create an order.

当需要填写新订单时,您会怎么做? 理想情况下,每次要创建订单时,您都将有一个用于此表单的空白模板,并打开一个新副本。

In real life, that doesn’t always happen, from what I’ve seen. People don’t have templates, or can’t find them, or don’t know how to use them. So, they just make a copy of an old order, and clear out the data, to make a new order.

从我所见,在现实生活中,这并不总是发生。 人们没有模板,或者找不到模板,或者不知道如何使用它们。 因此,他们只是复制一个旧订单,并清除数据以创建一个新订单。

If you want to clear out the old data, without deleting the formulas, how would you do it?

如果要清除旧数据而不删除公式,您将如何处理?

选择没有公式的单元格 (Select the Cells Without Formulas)

On this sheet, the formula cells are locked, and the sheet is protected. If you select the entire pricing section, and press Delete, Excel shows you a warning message, and doesn’t clear the cells.

在此工作表上,公式单元格被锁定,并且工作表受到保护。 如果选择整个定价部分,然后按Delete键,则Excel将显示警告消息,并且不会清除单元格。

Some of the selected cells are locked, so it can’t clear any of the cells.

某些选定的单元格已锁定,因此无法清除任何单元格。

clearconstants02

To select only the data entry cells, you can use the built-in Constants selector.

要仅选择数据输入单元,可以使用内置的“常数”选择器。

  • Select all the cells in the pricing section

    选择定价部分中的所有单元格
  • On the Home tab of the Ribbon, click Find & Select (at the far right)

    在功能区的“主页”选项卡上,单击“查找并选择”(在最右侧)
  • Click Constants, to select just the cells without formulas

    单击常量,仅选择没有公式的单元格
clearconstants03
  • Then, press the Delete key, to clear those cells.

    然后,按Delete键,以清除那些单元格。

命名数据输入范围 (Name the Data Entry Ranges)

Another option is to create a named range that contains all the data entry cells. Later, you can select that range and clear it.

另一个选择是创建一个包含所有数据输入单元格的命名范围。 以后,您可以选择该范围并清除它。

To name the range:

命名范围:

  • Unprotect the worksheet

    取消保护工作表
  • Select the data entry cells

    选择数据输入单元格
  • Click in the Name Box (at the left of the formula bar)

    单击名称框(在编辑栏的左侧)
  • Type a one-word name for the range, e.g. DataEntryCells

    输入范围的一字名称,例如DataEntryCells
  • Press Enter, to complete the name

    按Enter键完成名称
  • Protect the worksheet

    保护工作表
clearconstants04

To clear the named range:

要清除命名范围:

  • In the Name Box, click the drop down arrow

    在名称框中,单击下拉箭头
  • Select the range name – DataEntryCells – to select the cells

    选择范围名称– DataEntryCells –选择单元格
  • On the keyboard, press the Delete key, to clear the cells

    在键盘上,按Delete键,以清除单元格
clearconstants05

记录清理宏 (Record a Cleanup Macro)

If you’re building a data entry sheet for someone else, you can add a “Clear” or “Reset” button to the worksheet. That might deter people from wandering around the worksheet, trying to clear things on their own!

如果要为其他人构建数据输入表,则可以在工作表中添加“清除”或“重置”按钮。 这可能会阻止人们在工作表上四处徘徊,试图自己清除问题!

To create the macro:

创建宏:

  • Unprotect the worksheet, if it’s protected.

    取消保护工作表(如果已保护)。
  • Turn on the macro recorder, and name the macro

    打开宏记录器,并命名宏
  • Select the named range, and press the Delete key, to clear the cells.

    选择命名范围,然后按Delete键以清除单元格。
  • Select the first cell in the data entry range, so you’re ready to enter new data

    选择数据输入范围中的第一个单元格,这样就可以输入新数据了
  • Turn off the macro recorder

    关闭宏录制器

To create the button:

要创建按钮:

  • Add a rounded rectangle to the worksheet, with the caption “Clear”

    在工作表上添加一个圆角矩形,标题为“清除”
  • Right-click on the rectangle, and click Assign Macro

    用鼠标右键单击矩形,然后单击分配宏
  • Select the macro that you recorded, and click OK

    选择您录制的宏,然后单击“确定”。
  • Click on the worksheet, to unselect the button

    单击工作表,以取消选择按钮
  • Protect the worksheet again, if you removed the protection

    如果删除了保护,请再次保护工作表
clearconstants07

Save the File

保存文件

If you store a macro in your workbook, you’ll have to save it in Macro-enabled (xlsm) or binary (xlsb) format.

如果将宏存储在工作簿中,则必须将其保存为启用宏(xlsm)或二进制(xlsb)格式。

clearconstants06

翻译自: https://contexturesblog.com/archives/2014/03/20/clear-cells-and-leave-formulas/

vb清除单元格

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值