Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 停止时间自动更新与修正_Vba_Excel - Fatal编程技术网

Vba 停止时间自动更新与修正

Vba 停止时间自动更新与修正,vba,excel,Vba,Excel,我当前正在使用以下宏: Private Sub Worksheet_Change(ByVal Target As Range) Dim x As Long x = Target.Row If Target.Column = 2 Or Cells(x, 15) <> "" Or Target.Column = 3 Or Cells(x, 15) <> "" Then Cells(x, 1) = time Cells(x, 1).NumberFormat = "h:mm AM

我当前正在使用以下宏:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Long
x = Target.Row
If Target.Column = 2 Or Cells(x, 15) <> "" Or Target.Column = 3 Or Cells(x, 15) <> "" Then
Cells(x, 1) = time
Cells(x, 1).NumberFormat = "h:mm AM/PM"
End If
End Sub
这是伟大的,我想电子表格做的第一个实例,但现在我需要更多的修改。 我想:

从单元格A1和A2中删除宏

可能是困难的部分,一旦在B栏中输入了条目,如果需要进行修改,即发现拼写错误,时间戳将更新以反映最后的更改。是否可以更改宏,使A列中输入的时间戳不会与B列中的第一个条目发生更改

目前,如果在B列中输入了任何内容,宏将填充时间。我无法找到一种方法,使它不会在每次修改时“覆盖”时间

希望你们能帮忙

非常感谢

Private Sub Worksheet_Change(ByVal Target As Range)
Dim x As Long
x = Target.Row
If Target.Column = 2 Or Cells(x, 15) <> "" Or Target.Column = 3 Or Cells(x, 15) <> ""   Then
    if Cells(x, 1) = "" then
        Cells(x, 1) = time
        Cells(x, 1).NumberFormat = "h:mm AM/PM"
    End If
End if
End Sub

你可以试试这样的

谢谢你,但我似乎无法让它工作。当我保存宏并尝试输入数据时,如果没有结束IfMy bad,我会得到一个错误块,我解决了:只需要在End Sub之前添加一个额外的结束If。我非常感谢您在这方面的帮助。现在我看到了代码,它看起来很简单。再次感谢你