Not all cells are going to be populated, and ones that don't will be undef, as you are seeing, not a cell object. Try it on a specific cell that you know has content. Or better yet, one you know is merged and one you know has content but is not merged.