I'm writing a c# Add in for excel that takes values from a column of an excel sheet and does some operations. This is a part of the code that I wrote:
Excel.Range aqRange = currentSheet.Range["C3:C" + cRowCount];
Excel.Range vcRange = currentSheet.Range["D3:D" + cRowCount];
Excel.Range k0R = currentSheet.Range["F2"];
double[] sgVett = new double[cRowCount];
foreach (Range aq in aqRange)
{
if (i == 0) sgVett[i] = k0R.Value + aq.Value;
else sgVett[i] = sgVett[i - 1] + aq.Value;
i++;
}
i = 0;
foreach (Range vc in vcRange)
{
if (i == 0) sgVett[i] -= vc.Value;
else sgVett[i] -= vc.Value;
i++;
}
I want to know if is there some way to do something like this:
for(int j = 0; j<cRowCount; j++) {
if (i == 0) sgVett[i] = k0R.Value + aqRange[i].Value;
else sgVett[i] = sgVett[i - 1] + aqRange[i].Value;
}
I know that I can't use a Excel.Range
as a vector, but is there some way to use an index to scroll aqRange
and vcRange
or, at least, if it's possible to use just one for
or one foreach
instead of two (as I done).