VBA简单Range(“a”).Value2 = Range(“b”).Value2突然停止工作
在下面的子中 - 只需将一个命名范围复制到另一张纸上的另一个命名范围 - 一直有效。现在显然发生了一些变化,它引发了未指定的运行时错误
Sub prime_current_sim_input()
With Range("varianten_in")
.Value2 = Range("sim_direktinput_vals").Value2
End With
End Sub
相比之下,以下工作好吧,
Sub prime_current_sim_input()
Sheets("SIM").Select
Range("$B$3:$GN$3").Select
Selection.Copy
Sheets("Varianten").Select
Range("H3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
我完全不知道是什么原因造成的? 我已经检查过:
- 第一种方法之前在我的机器上有效,并且仍然适用于其他
- 所有其他子程序,在其他命名范围上以类似的方式工作也会引发相同的错误
- 工作得很好
- 我有同一文件的以前版本,在Windows上 10,excel 2016。
- 命名范围维度/地址没有改变并且是正确的,它们对应。
- 所有涉及的命名范围都是在工作簿级别定义的
另一个无效代码的示例,相同的错误
Public Function Save_variant_inputs(offset As Integer) As Boolean
' copy row to primer range "varianten_in"
With ThisWorkbook.Worksheets("Varianten").Range("varianten_in")
.offset(offset).Value2 = .Value2
End With
Save_variant_inputs = True
End Function
这是所涉及范围的视图:我不明白为什么这不起作用,它可以是具有权限的东西吗,工作表保护(两者都关闭)
该错误发生在所有类型的行中,
Range("a").Value2 = Range("b").Value2
无论子类型如何和函数被称为(直接从 vba 和通过按钮都会产生相同的结果)
因为这段代码在我没有接触它的情况下就崩溃了,我怀疑原因位于其他地方,与代码本身无关。 之前它就已经工作了,在那里,它工作得很好。
在我将子添加到另一个工作簿
in the following sub - that simply copies one named range to another on a different sheet - has always worked. now apparently something changed and it throws an unspecified runtime error
Sub prime_current_sim_input()
With Range("varianten_in")
.Value2 = Range("sim_direktinput_vals").Value2
End With
End Sub
In Contrast, the following works fine
Sub prime_current_sim_input()
Sheets("SIM").Select
Range("$B$3:$GN$3").Select
Selection.Copy
Sheets("Varianten").Select
Range("H3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
i'm at a complete loss as to what might cause this?
ive already checked:
- the first method has worked on my machine before and still works on others
- All other subs, that work in a similar fashion on other named ranges also throw the same error
- I have previous versions of the same file that work just fine
- windows 10, excel 2016.
- the named range dimensions/addresses haven't changed and are correct, they correspond.
- all involved named ranges are defined on workbook level
Another Example of not working code, same error
Public Function Save_variant_inputs(offset As Integer) As Boolean
' copy row to primer range "varianten_in"
With ThisWorkbook.Worksheets("Varianten").Range("varianten_in")
.offset(offset).Value2 = .Value2
End With
Save_variant_inputs = True
End Function
Here is a view of the involved ranges: i dont see why this wouldnt work, can it be something with permission, sheet protection (is off on both)
overwatch screenshot of involved ranges
The error occurs in all lines of type
Range("a").Value2 = Range("b").Value2
it makes no difference how the subs and functions are called (both from vba directly and via a button yields the same result)
since this code broke without me touching it i suspect the cause is located somewhere else, not related to the code itself. it has worked before
i have added the sub to another workbook and there, it works fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论