+ Reply to Thread
Results 1 to 6 of 6

.Value Not Capturing Leading Zero

  1. #1
    Registered User
    Join Date
    10-03-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    44

    .Value Not Capturing Leading Zero

    Hi All,

    I am attempting to do the following.

    Range("A1").value = "050" this returns a result of 50.

    I then try Range("A1").value=Cstr("050") again this returns a result of 50.

    How can I keep the leading zeroes?
    Last edited by Excel Guy 123; 09-12-2014 at 08:20 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: .Value Not Capturing Leading Zero

    Use .text value is the value text is what is displayed
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: .Value Not Capturing Leading Zero

    Perhaps:-
    Please Login or Register  to view this content.
    Regards Mick

  4. #4
    Registered User
    Join Date
    10-03-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: .Value Not Capturing Leading Zero

    I tried Range("A1").text ="050" and it returned a VBA error.

  5. #5
    Registered User
    Join Date
    10-03-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: .Value Not Capturing Leading Zero

    The number format did work.

    I actually found using "'050" (' before 050) worked as well.

    Thanks all for the help.

  6. #6
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373

    Re: .Value Not Capturing Leading Zero

    Hi

    You probably have the cell formatted as General or Number and that's why the leading zero is discarded.

    If you specify that the cell format is text you should not have problems with leading zeros.

    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)

Similar Threads

  1. [SOLVED] Capturing SQL return.....
    By swoop99 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-14-2013, 11:06 AM
  2. Capturing a temporary value
    By metalrat in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-21-2010, 07:28 PM
  3. Capturing Data
    By mikello in forum Excel General
    Replies: 2
    Last Post: 10-22-2009, 05:13 AM
  4. Capturing Keys
    By Phil_V in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-19-2009, 08:38 AM
  5. capturing row delete
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2008, 11:10 PM

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