I'm using the trick described here - !A1
- to get the the range of cells up to and including the current one (typically for a Rows() function). This works great for day to day usage, and eliminates a lot of errors that I get when moving ranges around when I previously had to use an adjacent set of rows.
Unfortunately, my formulas need to be evaluatable from VBA. With __THISCELL__
as my !A1
cell, and the cell housing the formula as $Z$100
the following evaluates to an error:
Application.Evaluate(rngCell.formula)
And the following evaluates to $A$1:$Z$50
rngCell.Worksheet.Evaluate(rngCell.formula)
Obviously an approach is to replace __THISCELL__
with rngCell.Address(External:=True)
prior to evaluation, but here's the kicker: I'd like to be able to execute my formula parser in a workbook which uses, say THIS_CELL
, THISCELL
or __THISCELL
safely, and I'd also like to be able to safely execute my code in a workbook with a name like __NOT__THIS_CELL__
.
All I need for this is a mechanism to evaluate relative references relative to a specific cell address - which since people do use R1C1 references in VBA a fair bit, I imagine must be around. However, I don't know it. Can anyone help?
NB: I like to avoid fiddling with ActiveCell
, Selection
, etc. where possible, since those smell like the excel equivalent of SendKeys
- who knows what the user is doing when you access them. Even then, though, I'm not certain I'll get the right answer, because for the Worksheet.Evaluate
approach, I'm not positioned in cell $A$1!