Vba excel专用子工作表\u更改不起作用
我的Excel工作表中有一个VBA sub,它应该查找给定列中的更改,如果它看到更改,则将日期和时间(从Vba excel专用子工作表\u更改不起作用,vba,excel,date,Vba,Excel,Date,我的Excel工作表中有一个VBA sub,它应该查找给定列中的更改,如果它看到更改,则将日期和时间(从Now())添加到另一列中的相应单元格中。此子项在两个位置检查更改,并根据更改的范围更新不同的单元格(如果G列更改,则更新a列;如果K列更改,则更新M列) 我没有收到任何错误或任何东西,只是没有将日期和时间添加到相应的单元格中。我的代码如下。我一辈子都搞不清楚它到底出了什么问题。它在几天前起作用了,从那以后我一直没能让它起作用 Private Sub Worksheet_Change(ByVa
Now()
)添加到另一列中的相应单元格中。此子项在两个位置检查更改,并根据更改的范围更新不同的单元格(如果G列更改,则更新a列;如果K列更改,则更新M列)
我没有收到任何错误或任何东西,只是没有将日期和时间添加到相应的单元格中。我的代码如下。我一辈子都搞不清楚它到底出了什么问题。它在几天前起作用了,从那以后我一直没能让它起作用
Private Sub Worksheet_Change(ByVal Target As range)
Dim cell As range
'Adds unique keyA values
'Check to see if the changed cell is in column G
If Not Intersect(Target, range("G:G")) Is Nothing Then
For Each cell In Target.Cells
If cell.Value <> vbNullString And Target.Row > 7 And Target.Row <= 20 Then
'Update the "KeyA" value
sheets("Front End").range("A" & Target.Row).Value = Now()
End If
Next cell
Else
'Adds unique keyB values
'Check to see if the changed cell is in column K
If Not Intersect(Target, range("K:K")) Is Nothing Then
For Each cell In Target.Cells
If cell.Value <> vbNullString And (Target.Row > "7" And Target.Row <= "27") Then
'Update the "KeyM" value
sheets("Front End").range("M" & Target.Row).Value = Now()
End If
Next cell
End If
End If
End Sub
可能您正试图实现以下目标:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cell As Range
'Adds unique keyA values
'Check to see if the changed cell is in column G
If Not Intersect(Target, Range("G:G")) Is Nothing Then
For Each cell In Target.Cells
If cell.Value <> vbNullString And Target.Row > 7 And Target.Row <= 20 Then
'Update the "KeyA" value
Range("A" & Target.Row).Value = Now()
End If
Next cell
Else
'Adds unique keyB values
'Check to see if the changed cell is in column K
If Not Intersect(Target, Range("K:K")) Is Nothing Then
For Each cell In Target.Cells
If cell.Value <> vbNullString And (Target.Row > "6" And Target.Row <= "27") Then
'Update the "KeyM" value
Range("M" & Target.Row).Value = Now()
End If
Next cell
End If
End If
End Sub
Private子工作表\u selection更改(ByVal目标作为范围)
暗淡单元格作为范围
'添加唯一的keyA值
'检查更改的单元格是否在G列中
如果不相交(目标,范围(“G:G”))则为零
对于Target.Cells中的每个单元格
如果cell.Value vbNullString和Target.Row>7和Target.Row是正确工作表下的函数,是否调用该函数?如何更改数据?手动或通过公式重新计算?该函数位于正确的工作表下,未被调用。当用户点击UserForm中的某个按钮时,数据会发生变化。您没有指定要更新的工作表。如果用户使用的是表单,那么ActiveSheet可能不是您认为的那样;使用要更新的工作表名称完全限定您的范围
s和单元格
等。按钮代码如何更新G列?B列加上三列(偏移量(0,3)
)是E列,对吗无论如何,请尝试移除保护。它可能会阻止工作表\u Change
更改受保护的工作表。它们在哪些方面不同,用户没有选择单元格并对其进行更改,一个公式正在更改单元格。在一个子元素将不同单元格的值加1或减1后,没有修复它,我做了第一行“selectionChange”当这些值为空时,它仍然不会更新A或M列changed@Vbasic4now在代码中,还应该更改第7行和第20行之间的行中的值。我已经检查了代码,它正在工作。试着用一个小的停止单元,看看你从哪里逃出if-s。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cell As Range
'Adds unique keyA values
'Check to see if the changed cell is in column G
If Not Intersect(Target, Range("G:G")) Is Nothing Then
For Each cell In Target.Cells
If cell.Value <> vbNullString And Target.Row > 7 And Target.Row <= 20 Then
'Update the "KeyA" value
Range("A" & Target.Row).Value = Now()
End If
Next cell
Else
'Adds unique keyB values
'Check to see if the changed cell is in column K
If Not Intersect(Target, Range("K:K")) Is Nothing Then
For Each cell In Target.Cells
If cell.Value <> vbNullString And (Target.Row > "6" And Target.Row <= "27") Then
'Update the "KeyM" value
Range("M" & Target.Row).Value = Now()
End If
Next cell
End If
End If
End Sub