Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel Automation AutoSum
Message
From
21/09/2011 08:29:46
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
20/09/2011 13:58:30
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01524059
Message ID:
01524125
Views:
133
>I would like to enter a SUM formula in an Excel spreadsheet use automation. I will not know how many rows are to be summed so I want to enter the formula similar to Excel's AutoSum feature where it automatically finds the starting point of the column and fills in the formaula. Is there a way to do this?
>
>Thanks,
>Robert

Formulae should usually be entered with relative references. Also, it is simpler to enter them in the R1C1 syntax - this is what you get when you record an Excel macro, so you can (a) record a macro, (b) insert a sum, and (c) look at the results. Basically, you have to calculate how many rows you need, and replace the corresponding part of the formula with the number of rows. Thus, for adding the three cells above, Excel gives:
ActiveCell.FormulaR1C1 = "=SUM(R[-3]C:R[-1]C)"
In Visual FoxPro, this becomes something like this, assuming you already have the variable to the current spreadsheet:
#define xlColumnE 5
oSheet.Cells(lnRow, xlColumnE).FormulaR1C1 = "=SUM(R[-" + trans(lnRowCount) + "]C:R[-1]C)"
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform