Pay attention on your variable trnsCount
:
// trnsCount = Rows.Count
int trnsCount = JobDataSheet.Rows.Count;
// trnsCount = 12
trnsCount = JobDataSheet.Cells[trnsCount, 1].End(Excel.XlDirection.xlUp).Row;
Then, after removing duplicates, you're using trnsCount
(which is equal to 12
) to get last row:
MyCount = JobDataSheet.Cells[trnsCount, 1].End(Excel.XlDirection.xlUp).Row;
and obviously this is incorrect, since you should use Rows.Count
instead 12
.
So, just change above line to:
MyCount = JobDataSheet.Cells[MyCount , 1].End(Excel.XlDirection.xlUp).Row;