I'm transferring data from a VB form into an Excel spreadsheet. Clicking OK on the form adds a new row to the spreadsheet containing the form data. Some of the spreadsheet cells, though, need to calculate their values from the form data; i.e., they contain formulas. So in the VB script I've included those cells and their formulas.
But when VB puts a formula into the spreadsheet, the cell references are not relative. For example, in the spreadsheet the formula in row 1 might be
=A1*26
In the VB script, if I just put
in the new row 2 in the spreadsheet it still uses the value from the old row's cell A1, not the new row's A2.
So I've added an Offset to the VB formula, and VB doesn't complain about my syntax but in the pertinent spreadsheet cell I'm getting a #NAME? error now.
Here's a portion of the VB script. I've colored the Offset bits:
So my question is, What's the best way to produce a relative cell reference in a VB script?
Bookmarks