简体   繁体   English

当填充另一个单元格时,自动将值设置为Excel中的空单元格

[英]Automatically set value to empty cells in Excel when another cell is populated

I have a spreadsheet that tracks certain information that is on a shared network drive. 我有一个电子表格,可以跟踪共享网络驱动器上的某些信息。 When a user adds a row, specifically be entering data into the next available row, cell B, I want to set a few other cells to default values. 当用户添加一行,特别是将数据输入到下一个可用行(单元格B)时,我想将其他一些单元格设置为默认值。 For instance, cell A should be a 1up number, cell C should be the user name, and cell D should be the current date, time stamp. 例如,单元格A应该是1up数字,单元格C应该是用户名,单元格D应该是当前日期和时间戳。

Individually, I know how to do all the pieces, but I do not know how to set those cells when cell B is changed from blank to not blank. 个别地,我知道如何进行所有操作,但是当单元格B从空白更改为非空白时,我不知道如何设置这些单元格。

I am not opposed to using VBA, but would like to avoid it if possible. 我不反对使用VBA,但希望尽可能避免使用它。

Some of the things you wish to record are easier with VBA . 使用VBA,您希望记录的某些内容会更容易。 I would use the following worksheet event macro: 我将使用以下工作表事件宏:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim s As String

    If Intersect(Target, Range("B:B")) Is Nothing Then Exit Sub
    ary = Split(Environ("homepath"), "\")
    s = ary(UBound(ary))
    Application.EnableEvents = False
        With Target
            .Offset(0, -1).Value = .Offset(-1, -1).Value + 1
            .Offset(0, 1).Value = s
            .Offset(0, 2).Value = Now
        End With
    Application.EnableEvents = True
End Sub

在此处输入图片说明

Because it is worksheet code, it is very easy to install and automatic to use: 因为它是工作表代码,所以非常易于安装和自动使用:

  1. right-click the tab name near the bottom of the Excel window 右键单击Excel窗口底部附近的选项卡名称
  2. select View Code - this brings up a VBE window 选择查看代码-这将打开一个VBE窗口
  3. paste the stuff in and close the VBE window 将内容粘贴并关闭VBE窗口

If you have any concerns, first try it on a trial worksheet. 如果您有任何疑问,请先在试用版工作表上尝试一下。

If you save the workbook, the macro will be saved with it. 如果您保存工作簿,则宏将随其一起保存。 If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx 如果您在2003年以后使用Excel版本,则必须将文件另存为.xlsm而不是.xlsx

To remove the macro: 删除宏:

  1. bring up the VBE windows as above 如上调出VBE窗口
  2. clear the code out 清除代码
  3. close the VBE window 关闭VBE窗口

To learn more about macros in general, see: 要总体上了解有关宏的更多信息,请参见:

http://www.mvps.org/dmcritchie/excel/getstarted.htm http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx http://msdn.microsoft.com/zh-CN/library/ee814735(v=office.14).aspx

To learn more about Event Macros (worksheet code), see: 要了解有关事件宏(工作表代码)的更多信息,请参见:

http://www.mvps.org/dmcritchie/excel/event.htm http://www.mvps.org/dmcritchie/excel/event.htm

Macros must be enabled for this to work! 必须启用宏才能使其正常工作!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel-如何在突出显示具有相等值的单元格时自动突出显示单元格 - Excel - How to automatically highlight cells when a cell with equivalent value is highlighted excel:比较两个单元格的值,并在另一个单元格中设置值 - excel: comparing the value of two cells, and set the value in another cell 当单元格的总和达到 Excel 中另一个单元格的值时突出显示单元格 - Highlight cells when its sum reached the value on another cell in Excel EXCEL VBA-遍历一行中的单元格,如果不为空,则将单元格值复制到另一行,直到下一行不为空 - EXCEL VBA - Loop through cells in a row, if not empty, copy cell value into another row until next row not empty Excel - 在更改另一个单元格值时自动将值输入到单元格/列中 - Excel - Entering Values Automatically into Cells/Columns upon Changing Another Cell Value 填充一个或多个单元格时如何自动向excel单元格添加文本? - How to add a text automatically to an excel cell when a cell or cells are filled? EXCEL VBA - 遍历列中的单元格,如果不为空,则将单元格值打印到另一列中 - EXCEL VBA - Loop through cells in a column, if not empty, print cell value into another column 单元格填充后如何自动将文本添加到Excel单元格? - How to add a text automatically to an Excel cell when cells are filled? 在另一个单元格中有特定值时计数单元格 - Counting cells when in another cell there is specific value 仅当另一个单元格上有值时才减去单元格 - Subtracting cells only when there is a value on another cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM