【问题标题】:Automatic date update in a cell when another cell's value changes (as calculated by a formula) (CONTINUED)当另一个单元格的值发生变化时自动更新单元格中的日期(通过公式计算)(续)
【发布时间】:2015-12-05 22:29:35
【问题描述】:

所以我想把这个问题添加到现有的question,但你需要一个 50 分,所以我不得不开始一个新的。我道歉。

有人发布了这段代码,它很好用,但是我想用日期和时间填充的字段在另一张纸上。我想知道是否有人可以告诉我要更改什么来确定需要更改的工作表。单元格偏移量也关闭了,因为要在 sheetA 上更新的字段需要在 sheetB 上的同一单元格中使用 Now()。

这是上一篇文章的代码:

Private Sub Worksheet_Change(ByVal Target As Range)
 Dim R1 As Range
 Dim R2 As Range
 Dim InRange As Boolean
    Set R1 = Range(Target.Address)
    Set R2 = Range("C2:C20")
    Set InterSectRange = Application.Intersect(R1, R2)

  InRange = Not InterSectRange Is Nothing
     Set InterSectRange = Nothing
   If InRange = True Then
     R1.Offset(0, 1).Value = Now()
   End If
     Set R1 = Nothing
     Set R2 = Nothing
 End Sub

谢谢!

【问题讨论】:

  • edit您的帖子链接到上一个帖子。当你这样做时,请选择更好的标签。这是vba吗? VB?擅长? c#?
  • So I wanted to just add this question to the existing question but you need a 50 rating - 将您的问题编辑成其他人的问题最终可能会被禁止。

标签: excel datetime vba


【解决方案1】:

假设Sheet2 是您的SheetB。你只需要改变一行。

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim R1 As Range
    Dim R2 As Range
    Dim InRange As Boolean
    Set R1 = Range(Target.Address)
    Set R2 = Range("C2:C20")
    Set InterSectRange = Application.Intersect(R1, R2)

    InRange = Not InterSectRange Is Nothing
    Set InterSectRange = Nothing
    If InRange = True Then
        'R1.Offset(0, 1).Value = Now()  '<-- Commented
        Sheets("Sheet2").Range(Target.Address).Offset(0, 1).Value = Now()   '<-- Added
    End If
    Set R1 = Nothing
    Set R2 = Nothing
 End Sub

【讨论】:

  • 完美!谢谢!!
  • 如果这个答案对你有帮助,请accept the answer 让其他人知道你现在有答案。
  • 这确实有效......但是......我试图在移动设备上运行工作表(这是它需要运行的),显然你不能在移动设备上运行 VBA Excel 版本。所以,除非有人能指出我在 Android 设备或 iPad 上运行的 Excel 版本,否则我实际上需要完成与没有代码的代码相同的事情......这可能吗?
猜你喜欢
  • 2012-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多