Hi, I have to delete some excel rows based on on cell value .I tried diffrent code and following too. But i get the error.I am using excel Interoperability
"Cannot perform Run time binding on a null refference"
All delete method i am getting same error.I dont understand what mistake i have done here
I have only 3 rows including heading. "DepDel " coloumn have value even other cells are optional and some of them are null
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);
}
}
I was also looking a solution like Autofilter.I couldnt see anything like this(!="somevalue")
excelRange.AutoFilter(9, cellvalue !="09", Excel.XlAutoFilterOperator.xlFilterValues, Type.Missing, true);