Thank you all for replying. I tried to add NOW() as parameter to the macro
functions but the cell value does not change - obviously, simply changing
cell selection is not enough to force recalculation. I thought there is a
variable or
object that can be used in worksheet formula as reference to active cell
just like ActiveCell object is in macros.
I used SelectionChange event before and found it good but I wanted to avoid
it for a couple of reasons.
1. When I used it before, the sheet that contained event or my macro modules
often got corrupted and the whole sheet needed rebuilding on a regular
basis. It was rather painful so I hoped there is another way. The code
corruption problems seemed to have stopped after I removed event processing
from my sheets (I used SelectionChange and WorksheetChange).
2.Ideally, this sheet using activecell references, would be often deleted
and recreated by other macros, which means the event coding would be lost in
the process. The macro that deletes and recreates the sheet can place
formulas in cell A1, A2 but it can not (or at least I don't know how to),
put the event code back in the sheet module.
3. Performance consideration. Even if using selective processing (If
Target.Row=3 then FunctionName=ActiveCell.Row) I thought it might still slow
down the processing.
The big picture is, I copy and paste stock option information from my
broker's web site and process this information.
I make it look nice and clear, and add additional static information kept
elsewhere in the spreadsheet, about the stock and also produce some values
for each option (gamma, delta, theta, rho, vega, implied volatility and fair
value)
I do it by displaying all options for particular stock on my broker's site,
the Ctrl-A, Ctrl-C - highlight the whole screen, copy to clipboard, and
switch to excel, and invoke a macro by pressing a button placed on the
toolbar. The macro clears the temporary sheet by deleting and recreating
it, then using ClipboardPaste places the information copied from the web on
it and depending on what information was pasted, it invokes a series of
macros to format sheet, process information after formatting, and update
other sheets if required. I have found that Delete and Add on the temporary
sheet is better than ClearContents/ClearFormats - it keeps the worksheet
clean and lean. So this is why I wanted to avoid SelectionChange event - the
code will be lost each time the sheet is deleted and added.
It appears I can not do have both, automatic active cell reference and sheet
delete add. I think the solution will be to have a permanent sheet,
preformatted etc with the selection change code in it, and have the
information transferred from the temporary sheet after pasting, rather than
doing it directly on the temporary sheet.
This will keep selectionchange code in, and the performance issues can be
addressed by avoiding using Select method in macros that run on the sheet,
which will limit the invocation of the code to only when I click on cells
manually. It is slightly better than using custom function (ROWX) in
formulas, these also can slow down processing considerably (and are also
pain in the neck when debugging, as each time macro causes recalc the
debugger jumps to the function used in the cell formula)
The top 6 rows of the option display is the information related to all
options - that is, the underlying stock information, the bottom part
contains options, listed one line per option. Each line has option bid, ask,
price, expiry, strike, etc. I would like to able to click on the option name
(say cell A20) and cause the sheet to automatically display some more
information about that option in the top (static) part of the display. There
is several reasons for doing it this way, rather than listing these values
in each row alongside with the rest of the option-specific information.
1. I am running out of screen space, adding 7 more columns to the display
would either go off screen or if zoom was used, make all text too small and
hard to read.
2. These 7 values are not easily created. They are complicated and recursive
formulas and I wouldn't even try to attempt to calculate them for each row.
If each line contained 7 formulas to calculate them the recalc would
effectively kill it. So I resolved to have them in the top part of the
screen and calculate them on demand.
By "demand" I mean when I want to - and sure, I can have a button to invoke
macro, read the inputs, and display the values. But I am too lazy - this
would be a two step operation, I would have to first click on the selected
option row, or "trigger cell" then press the button to display - and I am
not happy with it. One step operation is much better - simple selecting the
trigger cell(s) should cause the values to appear on top. Two step operation
also requires one to remember to press the button, and if you forget to do
it, the values displayed on top could be interpreted as calculated for the
option currently selected where in fact they weren't.
Excel has a lot of "magic names" - predefined objects, variables and special
methods. One of those "magic names" is ActiveCell object in macros. But they
are not documented very well in the online help. For example, there is no
"ActiveCell" reference in my macro help file. Strange, but even database
search returns nothing. So I used to have a handy reference file I found on
the net which had them all listed, but I lost it.
The ideal solution would be such "magic name" for active cell that can be
referenced in workesheet formula without the use of any additional macro
coding but if there was, with the number of ideas I got in response, one of
you would mention it by now. So it looks like I have to settle for second
choice, selective use of SelectionChange event and avoid triggering it with
my macros
I would like to thank you all for taking time to read and solve my problem.
regards,
Jack