for (int i = 2; i <= Rows; i++) { var DepDel1 = (Excel.Range)xlWorksheetNew.Cells[i, 9]; string DepDel = DepDel1.Value2.ToString(); Excel.Range r = xlWorksheetNew.Range[xlWorksheetNew.Cells[i, 1], xlWorksheetNew.Cells[i, 10]]; if (DepDel == "01") { // if match, delete and shift remaining cells up: r.EntireRow.Delete(XlDeleteShiftDirection.xlShiftUp); } }
for (int i = 2; i <= Rows; i++)
for (int i = 0; i < Rows; i++) // the correct way to loop all rows { var DepDel1 = (Excel.Range)xlWorksheetNew.Cells[i, 9]; string DepDel = DepDel1.Value2.ToString(); if (!string.IsNullOrEmpty(FepDel)) { Excel.Range r = xlWorksheetNew.Range[xlWorksheetNew.Cells[i, 1], xlWorksheetNew.Cells[i, 10]]; if (DepDel.Equals("01")) { // if match, delete and shift remaining cells up: r.EntireRow.Delete(XlDeleteShiftDirection.xlShiftUp); } } }
null
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)