public partial class Form1 : Form { string selectedFile; int iRow, iCol = 1; object[,] valueArray; List list = new List(); void dowork() { Excel.Application excel = null; excel = new Excel.Application(); excel.Visible = true; Excel.Workbook wkb = null; wkb = Open(excel, selectedFile); Excel._Worksheet sheet = wkb.Sheets[1]; Excel.Range range1 = sheet.UsedRange; var arr1 = (object[,])range1.get_Value(XlRangeValueDataType.xlRangeValueDefault); List listnew = new List(); for (int i = 10; i <= arr1.GetLength(0) - 1; i++) { if (arr1[i, 1] != null) { if (arr1[i, 2] != null && arr1[i, 3] == null) { listnew.Add(new object[] { arr1[i, 1], "+ " + arr1[i, 2] + " ₹" }); } else if (arr1[i, 2] == null && arr1[i, 3] != null) { listnew.Add(new object[] { arr1[i, 1], "- " + arr1[i, 3] + " ₹" }); } } } // commented out because i started adding from element 10 and also loop stops before length -1 // list.RemoveAt(list.Count - 1); // list.RemoveRange(0, 10); // 6. copy text file data to list copydata(); // filter from only index which conatins names Filter(listnew, 1, list); // 1 is the index number which contains names } public void copydata() { string filename = "abc.txt.txt"; string filePath = @"C:\hello\" + filename; using (var file = new StreamReader(filePath)) { var line = string.Empty; while ((line = file.ReadLine()) != null) { list.Add(Convert.ToString(line, CultureInfo.InvariantCulture)); } } } public void Filter(List ws, int columnIndex, List values) { // compare both lists here }