【问题标题】:Excel VBA: Runtime Error 424, Object RequiredExcel VBA:运行时错误 424,需要对象
【发布时间】:2016-02-22 12:13:26
【问题描述】:

我无法解决这个问题。我之前遇到过类似的问题,原来我使用的是单个单元格的 Range,这是多余的。但在这种情况下,我需要 End(xlDown) 而我无法让它工作。我尝试了一些组合,但我无法找出正确的语法。帮忙?

Public Exceptions As Range
Public Xcept As Range

Sub Example()
Static ExcSh As Worksheet
Set ExcSh = Worksheets("ComboExceptions")
Set Exceptions = ExcSh.Range("A2")

Set Xcept = ExcSh.Range(Exceptions.Offset(1).Cells, Exceptions.Offset(1).Cells.End(xlDown))
'This is where the error happens ^
End Sub

【问题讨论】:

  • 删除.Cells的两个实例
  • 你没有从A3开始而不是A2然后.Offset(1)有什么原因吗?
  • 有一个很好的理由是的。不管怎样,我解决了。将立即发布答案。

标签: vba excel


【解决方案1】:

解决了!我已经声明了

Static ExcSh As Worksheet

在另一个 Sub 中,导致出错的函数无法访问。我将其公开,现在以下命令可以正常工作:

Set Xcept = ExcSh.Range(Exceptions.Offset(1), Exceptions.Offset(1).End(xlDown))

【讨论】:

  • 根据@Jeeped 上面的评论Set Xcept = ExcSh.Range(Exceptions, Exceptions.End(xlDown)) 如果您调整起点也足够了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多