Excel doesn't recognize leading 0s in front of numbers as part of that
number. If you enter in a cell 0012345, as soon as you hit enter Excel
strips off the leading 0s. The only way to have leading 0s *display* and the
number to still remain a number is to use a custom number format like
0000000. However, the leading 0s are *displayed* but are not part of the
true value of the cell.
If you format A1 as Custom 0000000 and enter 0012345 the *true* underlying
value of that cell is 12345. So, any formula referencing that cell "sees"
only the true underlying value of 12345.
You can get leading 0s to be recognized *if* you treat the entry as a *TEXT*
value. You can do this 2 ways. Precede the entry with an apostrophe like
this: '0012345. The apostrophe will not be displayed in the cell. Or, you
can pre-format the cell as TEXT.
So, if the entry is treated as TEXT and is in the form 0012345 then the
formula I suggested will work and it will convert the TEXT numbers to
numeric numbers.