[ACCEPTED]-Iterating through an Excel range-excel

Accepted answer
Score: 16

Since you are already getting the Range 5 object in your event handler, you don't 4 want to re-query the worksheet for your 3 range--you won't get the new values.

Instead, try 2 looping through the Range.Cells property, like 1 this:

foreach (Range c in Target.Cells)
{
   string changedCell = c.get_Address(Type.Missing, Type.Missing, XlReferenceStyle.xlA1, Type.Missing, Type.Missing);  
   MessageBox.Show("Address:" + changedCell + " Value: " + c.Value2);
}
Score: 5

To iterate the Range, it's 1-based, that 1 is:

for (int i = 1; i <= Target.Count; i++)
{
  Excel.Range r = (Excel.Range)Target.Item[i];
  MessageBox.Show(Convert.ToString(r.Value2));
}

More Related questions