Vba 从其他工作表中获取值
我在尝试使用此代码时遇到一些问题:Vba 从其他工作表中获取值,vba,excel,Vba,Excel,我在尝试使用此代码时遇到一些问题: Private Sub Worksheet_Change(ByVal Target As Range) Static ZeroFlag As Boolean Dim KeyCells As Range Set KeyCells = Range("B29") On Error Resume Next Set KeyCells = Application.Union(KeyCells, KeyCells.Precedents) On Error Go
Private Sub Worksheet_Change(ByVal Target As Range)
Static ZeroFlag As Boolean
Dim KeyCells As Range
Set KeyCells = Range("B29")
On Error Resume Next
Set KeyCells = Application.Union(KeyCells, KeyCells.Precedents)
On Error GoTo 0
If Not Application.Intersect(Target, KeyCells) Is Nothing Then
If (Range("B29").Value <= 0) Xor ZeroFlag Then
MsgBox IIf(ZeroFlag, "Not zero", "zero")
ZeroFlag = Not (ZeroFlag)
End If
End If
End Sub
Private子工作表\u更改(ByVal目标作为范围)
作为布尔值的静态零标志
暗淡的关键单元格作为范围
设置关键单元格=范围(“B29”)
出错时继续下一步
Set keycell=Application.Union(keycell,keycell.precements)
错误转到0
如果不是Application.Intersect(Target,KeyCells),则什么都不是
如果(范围(“B29”).Value没有在工作表中写入代码,您必须在工作簿中写入代码,更改如下:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
'....write your code here
End Sub
它起作用了
我修改了我使用的第一个代码,包括了一些其他的代码,结果是这样的
Private Sub Worksheet_Calculate() Static ZeroFlag As Boolean
If Range("B29").Value <= "0" Xor ZeroFlag Then
MsgBox IIf(ZeroFlag, "Not Zero", "Zero")
ZeroFlag = Not (ZeroFlag)
End If
End Sub
Private子工作表\u Calculate()静态零标志为布尔值
中频范围(“B29”).Value使用此工作簿中的evenhandler
moduleNice@KSSheon,似乎您只能获取对已更改的工作表的引用,而不能获取特定单元格的引用,显然可能有许多单元格已更改。它的可能副本也不起作用,如果我手动更改工作表上的值,则会显示警报,但如果我使用另一张工作表获取警报未显示的值您正在尝试从不同的工作表中删除单元格。您无法执行此操作。您没有收到错误,因为“下一步继续时出错”时出现了。
。当我从“更改”更改为“工作表”时,代码停止工作。它已编译,但即使在更改时也停止显示警报ge是在同一张工作表上完成的。我只是想确认您是否如我所述更改了“更改为工作表更改”或“工作表更改为工作簿更改”?我已从工作表更改为工作簿更改
Private Sub Worksheet_Calculate() Static ZeroFlag As Boolean
If Range("B29").Value <= "0" Xor ZeroFlag Then
MsgBox IIf(ZeroFlag, "Not Zero", "Zero")
ZeroFlag = Not (ZeroFlag)
End If
End Sub