本文介绍了Excel中的自动更新时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前正在处理一个工作表,如果另一个单元格为是",则该工作表必须将今天的日期自动插入一个单元格中.
I'm currently working on a sheet that has to automatically insert todays date in a cell, if another cell is = "Yes"
我目前有这行代码(是我在网上找到的):
I currently have this line of code (that I found online):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
If Not Intersect(Target, Range("G:G")) Is Nothing Then
Application.EnableEvents = False
For Each cell In Target
cell.Offset(0, 4).Value = Now
cell.Offset(0, 4).NumberFormat = "dd/mm/yyyy"
Next cell
End If
Application.EnableEvents = True
End Sub
问题在于,每次更改单元格时,都会更新K行中更新的单元格,并且仅当G行中的单元格为是"时才应更新它.
The problem is that the updated cell in row K is being updated every time the cell is changed, and it should only be updated when the cell in row G = "Yes"
我非常感谢您的帮助:)
I appreciate the help :)
推荐答案
考虑:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
If Not Intersect(Target, Range("G:G")) Is Nothing Then
Application.EnableEvents = False
For Each cell In Target
If cell.Value = "Yes" Then
cell.Offset(0, 4).Value = Now
cell.Offset(0, 4).NumberFormat = "dd/mm/yyyy"
End If
Next cell
End If
Application.EnableEvents = True
End Sub
我们测试每个条目的值!
We test the value of each entry!
这篇关于Excel中的自动更新时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!