+ Reply to Thread
Results 1 to 4 of 4

Macro to Check for Missing Leading Zero

  1. #1
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Macro to Check for Missing Leading Zero

    I have columns of phone numbers, some have a leading zero, others are missing their leading zero. The columns are all formatted as 'TEXT' and should remain so.

    I need a macro that will look at the selected column and if it already has a leading zero, it does nothing, but if their is no leading zero it adds one to the number (formatted as text), so

    0207456789 would remain the same
    207456723 would become 0207456723

    I have limited VBA knowledge...

    Many thanks

  2. #2
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Macro to Check for Missing Leading Zero

    Hi.

    Check this code:

    Please Login or Register  to view this content.
    Click *, if my suggestion helps you. Have a good day!!

  3. #3
    Forum Contributor
    Join Date
    06-21-2010
    Location
    -
    MS-Off Ver
    Excel 2010
    Posts
    1,211

    Re: Macro to Check for Missing Leading Zero

    Hi jraj1106,

    Thanks, that works, but how could I adapt the code to make it column indepenedent, i.e. to not need to change the column reference each time. I have numbers in numerous columns

    Also, is there a way to prevent it adding the zero if the cell is blank?

    Many thanks

  4. #4
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: Macro to Check for Missing Leading Zero

    Try this code:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1