【问题标题】:Automatically add the date a row was last changed/updated自动添加最后一次更改/更新行的日期
【发布时间】:2021-10-17 07:38:20
【问题描述】:

这里我有 3 列,当状态为“已售出”时,我需要添加编辑日期的公式/函数。例如,如果“Orange 1”的状态为“Sold”,则在其中放置更改日期。我需要enter image description here将此公式应用于所有单元格

【问题讨论】:

  • 我建议您阅读帮助中心文章“How do I ask a good question?”。我还建议您编辑您的问题以提高质量并更好地帮助 SO 社区提供答案。

标签: google-apps-script google-sheets timestamp


【解决方案1】:

试试这个:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim Index As Integer: Index = 2
    
    Do Until Range("B" & Index).Value = ""
        If Range("B" & Index).Value = "Sold" Then
             Dim dDate As Date: dDate = Date
        
            Range("C" & Index).Value = dDate
        End If
        Index = Index + 1
    Loop
End Sub

【讨论】:

    【解决方案2】:
    function onEdit(e) {
      const sh = e.range.getSheet();
      if(sh.getName() == 'Sheet Name' && e.range.columnStart == 2 && e.range.rowStart > 2 && e.value == 'Sold') {
        e.range.offset(0,1).setValue(new Date());
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-12
      • 2012-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多