+ Reply to Thread
Results 1 to 5 of 5

ERROR on formula to prevent csv file from dropping LEADING ZEROS

  1. #1
    Registered User
    Join Date
    09-10-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    86

    ERROR on formula to prevent csv file from dropping LEADING ZEROS

    I am writing the following macro that will add leading zeros to postal codes outside the US WHICH IN FACT DO use leading zeros. The reason for this is that my csv file drops leading zeros, so i am hard coding it
    I am getting a error on the ActiveCell.FormulaR1C1 = "=IF(L2="USA",RIGHT("00000"&L2,5),L9)"
    line PLEASE ASSIST

    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,833

    Re: ERROR on formula to prevent csv file from dropping LEADING ZEROS

    Double up the quotes:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,833

    Re: ERROR on formula to prevent csv file from dropping LEADING ZEROS

    Suggest you post a sample workbook. The code, I am sure could be a lot shorter than that.

    Not sure exactly where the formula is meant to be going but, as an example:

    Please Login or Register  to view this content.

    Regards, TMS

  4. #4
    Registered User
    Join Date
    09-10-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    86

    Re: ERROR on formula to prevent csv file from dropping LEADING ZEROS

    i have a raw file that comes in with postal codes that are missing numbers. basically for all the USA codes in column K2 all the way down that has a postal code less than 5 digits i would like to add "0" in place. so for code 345 it would be 00324. and so on.
    Column K1 HAS THE POSTAL CODE HEADER and K2 down is where the data is entered. Column L1 is country code an L2 below could be USA,BRA,JAM etc. Thus the below code which is giving a error on

    'ActiveCell.FormulaR1C1 = "IF(L2=""USA"",RIGHT(""00000""& K2 ,5)""K2"")"

    so the code should copy the formula from K2 all way in the record

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,833

    Re: ERROR on formula to prevent csv file from dropping LEADING ZEROS

    Adjust the code provided in post #3 to refer to the appropriate cells.

    Note that the formula is NOT in R1C1 format,, it is in A1 format so you need to use .Formula, not .FormulaR1C1

    Please Login or Register  to view this content.

    Change the x to refer to the column where you want the formula.


    Regards, TMS

+ 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. Dropping Leading zeros in date
    By researcy in forum Excel General
    Replies: 3
    Last Post: 10-03-2008, 11:28 AM
  2. Excel Dropping Leading Zeros
    By Tarball in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2007, 09:49 AM
  3. Formula Dropping Leading Zeros
    By Computer Lady in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2006, 07:13 PM
  4. Formula Dropping Leading Zeros
    By Computer Lady in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-26-2006, 05:40 PM
  5. How to prevent Excel from deleting leading zeros?
    By ljCharlie in forum Excel General
    Replies: 1
    Last Post: 10-31-2005, 07:05 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