[英]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: 因为它是工作表代码,所以非常易于安装和自动使用:
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: 删除宏:
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.