In this example, those would be 2 report variables that you set in code, before calling report.Run.
For example:
report.SetValue('FirstSheet', 'confetti');
report.SetValue('LastSheet', 'mylastsheet');
Of course, in practice it would be more like:
dataSet.Position := 0;
report.SetValue('FirstSheet', dataset.SheetName);
dataSet.Position := dataSet.RecordCount - 1;
report.SetValue('LastSheet', dataset.SheetName);
But I don't know what datasource you are using, it might also be List[0] and List[List.Count - 1], etc.
What is important is that you set the FirstSheet to be the string with the first sheet you want to sum and lastsheet with the last.
Note that you could also go even more generic and do something like:
report.SetValue('myformula', '=SUM('FirstSheet'!A1:'LastSheet'!A1');
And then in the template write
<#formula><#myformula>
I don't know the specifics on what formula do you exactly want to use, so I can't give you an exact answer, but ideas on how to get them. The important part is that the sheet names are available when you run the report, so you can really use any string with <#formula> tag: The <#formula> is needed because the formula wouldn't be possible to write in Excel when the template doesn't have those sheets, but when you use <#formula> what you need is that the formula is possible to write when running the report (and at that time, the sheet names are available).
You could even use stuff like <#list()> (
http://www.tmssoftware.biz/flexcel/doc/vcl/guides/reports-tag-reference.html#list ) to get a list of the sheets, and do a =Sum(sheet1!A1, Sheet2!a1...) but I would strongly recommend you NOT to do this. Formulas in Excel are limited to 8000 characters, and manually generating a string like the one above can easily break that limit. Besides the fact that it is much more error prone: If someone adds a new sheet it won't be included in the formula. So when possible, it is always better to use =SUM(FirstSheet:LastSheet!firstCell:lastCell) or similar.