Due to project restriction I can't share the actual code.
In that case we cannot help you as it is, probably, the error checking that is wrong or maybe you do actually have a column that meets the criteria - the values of which you have not shown. And please use the code tags when posting code and/or data. The true alignment shows up when used.
The problem I have is that people can explain things quickly but I can only comprehend slowly.