public Tuple <DateTime, DateTime, int, bool> CalPaymentPerPerson(int intPersonID, Excel.Excel.Worksheet xlWorkSheetFirst, Excel.Excel.Worksheet xlWorkSheetSecond, Excel.Excel.Worksheet xlWorkSheetThird) { DateTime dtStart; DateTime dtEnd; string strServiceName = null; currentFind = null; firstFind = null; bool blCheckInsurance = true; var result = Tuple.Create(DateTime.MinValue, DateTime.MinValue, intPersonID, blCheckInsurance); Excel.Excel.Range Fruits = xlWorkSheetFirst.get_Range("A1", "A42"); // Specify all these parameters every time you call this method, // since they can be overridden in the user interface. currentFind = Fruits.Find(intPersonID, misValue, Excel.Excel.XlFindLookIn.xlValues, Excel.Excel.XlLookAt.xlPart, Excel.Excel.XlSearchOrder.xlByRows, Excel.Excel.XlSearchDirection.xlNext, false, misValue, misValue); while (currentFind != null) { string strRowNumber = currentFind.get_Address(); strRowNumber = strRowNumber.Substring(strRowNumber.LastIndexOf('$') + 1); dtStart = Convert.ToDateTime(xlWorkSheetFirst.Cells[Convert.ToInt32(strRowNumber), 6].Value.ToString()); dtEnd = Convert.ToDateTime(xlWorkSheetFirst.Cells[Convert.ToInt32(strRowNumber), 7].Value.ToString()); strServiceName = xlWorkSheetFirst.Cells[Convert.ToInt32(strRowNumber), 3].Value.ToString(); Tuple <DateTime, DateTime, int, int, string, bool> userData = calservicefees(dtStart, dtEnd, intPersonID, strServiceName, xlWorkSheetSecond, xlWorkSheetThird); blCheckInsurance = userData.Item6; return(result = Tuple.Create(dtStart, dtEnd, intPersonID, blCheckInsurance)); //Check if person has insurance if (blCheckInsurance == true) { cal10euroeachday(dtStart, dtEnd, intPersonID); return(result = Tuple.Create(dtStart, dtEnd, intPersonID, blCheckInsurance)); } // Keep track of the first range found. if (firstFind == null) { firstFind = currentFind; } // If didn't move to a new range, done. else if (currentFind.get_Address(Excel.Excel.XlReferenceStyle.xlA1) == firstFind.get_Address(Excel.Excel.XlReferenceStyle.xlA1)) { break; } currentFind = Fruits.FindNext(currentFind); } return(result); }