Excel VBA Number Format

Posted on 2013-09-03
Medium Priority
Last Modified: 2013-09-10
I am having a problem with the number format for cell that is being cleared with VBA and then a raw report from Quickbooks is imported.  

The problem happens when a value with a leading zero is imported as a number.  For example: account number "0123456" is imported as "123456".  

I am stumped with how to force the formatting to be "Text" so that the number shows right.  At first glance this might seam like a simple line to format the data to text before it is placed on the worksheet would fix this but the report is simply being deposited into the sheet without addressing each value.  

Thanks for your help.
Question by:AccountantsTech
LVL 23

Accepted Solution

Michael Fowler earned 1000 total points
ID: 39462731
In your code you could add a single quote mark (') to the front of the number. This forces excel to display as a string.

To format the cell before inputing the value use

Range("A1").NumberFormat = "@"

Open in new window


Author Comment

ID: 39481391
I actually just went around this issue by running a post import routine that checks the length of the value and adds a leading zero if it is shorter.  All values should be 6 characters long.

Thank you for you help!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
What to do if a split doesn't fit? Or a bunch of invoice lines must be rounded while the sum must match a total? It takes a little, but - when done - it is extremely easy to implement.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question