如果我在工作表的单元格 A 中输入“已付款”文本,我想在单元格 B 中自动提取当前日期。如果单元格为空,则不应提取日期。喜欢:
--------------------------------------
A | B
--------------------------------------
Paid | 2/25/2018
----------------------------------
Paid | 2/26/2018
----------------------------------
empty cell |
----------------------------------
empty cell |
I tried to use =ArrayFormula(IF(A2:A81=paid),"paid",(NOW()))
Run Code Online (Sandbox Code Playgroud)
但得到错误。他们有什么办法吗?
尝试这个:
=ArrayFormula(IF(A2:A81="paid", NOW(),""))
Run Code Online (Sandbox Code Playgroud)
如果您永远不想更改日期,则需要使用如下脚本:
function onEdit() {
// writes the current date to the cell to the right on the row when a cell in a specific column is edited
// adjust the following variables to fit your needs
var sheetNameToWatch = "Sheet1";
var columnNumberToWatch = /* column A */ 1; // column A = 1, B = 2, etc.
var valueToWatch="paid";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
var val=sheet.getActiveCell().getValue()
if (sheet.getName() == sheetNameToWatch && range.getColumn() == columnNumberToWatch && val==valueToWatch) {
var targetCell = sheet.getRange(range.getRow(), range.getColumn()+1
);
targetCell.setValue("" + Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy"));
}
}
Run Code Online (Sandbox Code Playgroud)
没有办法用我知道的公式来做到这一点。它可以更短,但仍然需要脚本:
function onEdit(e) {
if (e.source.getSheetName()=="Sheet1" && e.range.getColumn() == 1 && e.range.getValue() == "paid") {
e.range.offset(0,1).setValue(new Date());
}}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16244 次 |
| 最近记录: |