+ Reply to Thread
Results 1 to 4 of 4

Retaining leading zeros in text cell problem

  1. #1
    Registered User
    Join Date
    03-25-2004
    Posts
    54

    Retaining leading zeros in text cell problem

    I am trying to put the next consecutive number into the cell below. The column is formatted as text and I need to retain the leading zeros e.g.

    I have simply used
    Please Login or Register  to view this content.
    . This works fine for, say, adding 1 to 3939 to give 3940, but if I try with 0001, I always get just 2 without the leading zeros. I have tried using the Format and Str functions with no success.

    I am sure there must be a simple solution to this.....

    Paul
    Last edited by VBA Noob; 12-24-2007 at 02:17 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Use a Custom Format - 0000
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Try
    Please Login or Register  to view this content.
    Automatic type conversion, as in your
    Please Login or Register  to view this content.
    is nice, but when things don't work right, specifing the heck out of everything is a good first step.


    P.S. "Please wrap code" includes even snippets like the one in your original post.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    03-25-2004
    Posts
    54
    Many thanks for your help. Sorry not to reply early but Christmas intervened...

    I hadn't mentioned but I also needed to select just the first 4 characters from the row above as they occasionally have a letter at the end. After adding the Left funtion, I couldn't get the code you gave to work without removing the Val function, but this does now work:

    Please Login or Register  to view this content.
    Thanks for your tip about specifing everything and I will wrap all code in future,

    Paul

+ 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