简体   繁体   中英

Excel VBA: Runtime Error 424, Object Required

I can't figure this issue out. I had a similar problem before, it turned out I was using a Range of a single cell, which was redundant. But in this case I need End(xlDown) and I can't get it to work. I tried a few combinations and I can't figure out the right syntax. Help?

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

Solved it! I had declared

Static ExcSh As Worksheet

in another Sub making it inaccessible to the function that errored. I made it public and now the following command works fine:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM