• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

SpecialCells method inside worksheet function?

BobBridges

Active Member
I'm updating a worksheet function for a client, and I've run into a problem. The old version of the function looked for a particular section in the worksheet and extracted a value from it. He wants the new version to search not just the one section but that and the next one too, so I thought I'd "improve" the logic by using a class method that maps the worksheet, section by section, and pull the two sections I want with less trouble.

Instead I'm having trouble. When the mapping method invokes the SpecialCells(xlCellTypeLastCell) method, it returns Cell(1, 1); it should be the last used cell on the worksheet, for example Cell(25, 8). The next statement tries for an Offset value of that cell, and it triggers an error ("Application-defined or object-defined error").

When I call this logic in a Sub, it works fine. Is there something about the SpecialCells method that prevents it from working properly inside a worksheet function? If so, I don't recall knowing it before.
 
Even if VBA SpecialCells method is somewhat limited and can be tricky the limitation does not come from this method …​
… but from using an UDF (user defined function) which has constraints.​
Like you can discover with this thread :​
 
Fine, it has constraints (which I half expected). But what are the constraints? Where do I find them documented?
 
As usual with a web search, starting with the mother source like​
And to optimize :​
 
Back
Top