Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Excel


VBA Format Number With Leading Zero

I have the following script which is working fine execpt for its limited to running the loop 10 times. The macro is looking for files where the file extension could be anything between .P01 and .P99. Currently, the macro looks for file.P01 then file.P02 etc until it gets to file.P09 by increasing the value of 'i'. The trouble I am having is to get the variable 'i' to have a leading zero when the value is less than 10.

Sub rename_print_files()

Dim OldName, NewName
Dim i As Integer
Dim strResult, strOldName, strNewName As String

Range("E14").Activate ' set first file
Application.DisplayAlerts = False

View Complete Thread with Replies

Sponsored Links:

Related Forum Messages:
Number Format To Keep Leading Zeros
I'm using Excel 2007 and am using a look up formula =isna(match( cell, cell range, 0)) to see whether a number in one column occurs in another column.

I have been doing this process successfully for over a year on Excel 2003 and more recently on Excel 2007. This is until today, when it's stopped doing what I expect - could I have changed a setting?

The correct number format for this sheet should be 0000 (so now '67' will appear as '0067' or '290' will appear as '0290' etc.) So I have applied this Custom Format to my columns: '0000'
After applying the Custom Format to the spreadsheet the numbers appear correctly - 560 now appears as 0560 - BUT in the formula bar they still only appear as the original format - so 560 is STILL 560 rather than 0560 as it should be!

As a result of this, my look up is not looking for the number in the new format, it's still looking for the number in its original format - so a look up for 0560 is actually returning results for anything with 560 in it: 560, 5600, 5601, 56000, 56007 etc.
I need my look up to be looking for 0560 NOT 560.

How do I force the numbers to become 4 digits in the formula bar so that my look up for 0560 only finds a match with a cell containing 0560 and not 560, 5600, 5601, 56000, 56007 etc.

View Replies!   View Related
Leading Zero(s) / Custom Format? ()
I'm having trouble with the leading zeros of my ISBN#s; excel keeps chopping them off. I found a topic that discussed this issue, but it won't work for me.

I can't format them as text because I'm getting them as an isbn with dashes (ie:978-05689-256-7) and when I remove the dashes (even if its formatted as text) excel changes the number to 9780568.9E+12 (or something like that)

I think the solution would be to create a custom format (ie. 0000000000) to preserve the zeros, but I'm having 2 problems:

1. Since the ISBN#'s have 2 different formats (ISBN-10 & ISBN-13) I need to somehow check if the first 3 numbers are 978 then based on that it should be formatted either as ISBN-10 (0000000000) or ISBN-13 (0000000000000)

2. In the post that I linked to above it said that I won't be able to do a vlookup if its custom formatted. Is there any way around this?

View Replies!   View Related
Leading Zeros Lost In Csv Format
I have an excel spreadsheet with numbers and the format has to show zeroes at the beginning (e.g. 0011111) It is always going to be a seven digit number. I can format the cells to show the numbers with the leading zeros, but as soon as I save the file as a csv, the leading zeros are lost.

Does anyone know how to the zeros can be retained when the file is saved in csv format?

View Replies!   View Related
Extracting Digits From A Number With Leading Zeroes
I need Excel to create Date's of Birth from following data in column A. If the data are 7 numbers long, I need to add a '0' to the start and have used the custom format of 0#######. This works fine but I need the data in column B to just display the first 4 digits. I have used =LEFT(A1,4) to do this, but it's not picking up the 0's which I've added.

View Replies!   View Related
Deleting Leading And Trailing Spaces From A Number
I am using the following code to import an excel file into an existing sheet. The problem I am having is the way some of the cells are being imported. Some of the cells have spaces before and after the number.

I need to delete the leading and trailing spaces for each cell affected. Is there a code I can incorporate to do this? BTWthe columns effected are columns F & G.

View Replies!   View Related
Converting Text To Number, Dropping Leading Zero
I have a macro that goes out to a database and pulls in updated numbers. However the numbers come in as text because they have leading 0's:


The only way I can get the numbers formatted as a number and drop the leading 0 is to click on the yellow exclamation tab that pops up and click, Convert to Number. Is there any way I can write this into my macro to automatically do for me? I tried selecting the column and reformatting this way but it would not drop the leading zero:

View Replies!   View Related
Join Text With Number With Leading Zeros
I'm trying to convert a set of numbers between 1 and 9999 into text strings, with the number at the end as a four digit string, so 1 becomes "COLUMN0001", 123 becomes "COLUMN0123", etc. In excel, it would be easy - I would just use the text function and convert the number to a string and append it to the word COLUMN, but as far as I know, there isn't an equivalent function in excel and running excel functions in VBA is notoriously slow (especially as I will need to do this about 360,000 times).

View Replies!   View Related
How To Insert Leading Zeroes Into Mixed Letter Number Field
I have a column of data that is given to me that is a mix of letters and numbers and I need the numbers to have leading zeros, they must all be three digits. The data has either 3, 4, or 5 letters followed by numbers 1 through 999. Example: ABCD7 I need to change it to ABCD007. I am using Excel 2004 for the Mac.

View Replies!   View Related
Save Number As Text In Txt Format Wo Changing The Format
In order to export an excel table into another program I first need to save the excel file as .txt. The .txt file can then be imported by the other program.

First I however need to make excel understand that the value should be a text and not a value. I therefore format the number as text (0000150235) by adding "0000150235". After saving the file as .txt the format changes from "0000150235" to """0000150235""". I do however need the format in the .txt file to be "0000150235". Can anyone tell me how I can save "0000150235" as .txt and get the value "0000150235" in the .txt file.

View Replies!   View Related
Format Number To Text With Specific Format
I'll get straight to the point: How can I change this text format from 474556788 to 0-47455678-8 (dash added after 0 and before the last number). I need to apply this to around 5000 rows (can't do that manualy). I want it to be int his format:

474556788 to 047-455678-8

Tks Auto Merged Post;474556788 to 047-455678-8 (This is the wanted format)

View Replies!   View Related
Join Text & Number & Retain Number Format
I used to get data from a database (CorVu & MIMS) in this format "0122458/001". Due to changes in those Databases I now get the data as 2 columns " 0122458" and "1" .What I need to do is somehow get this back to the old format including the leading zeros.

View Replies!   View Related
Format Cells So Number Shows As Number Over Zero
how do you place 100/0 so the /0 stays static and the 100 can be used to operate? (ie: 100/00, 101/00, etc)

View Replies!   View Related
Show Text & Number With Number Format
I have a standard block of text with numbers in it pulled from various calculations in a financial model. I have done this through a formula

e.g. ="You gross profit percentage is " & D9 & "% and your gross profit is $" & D10 & "." Problem is i'd like to format the numbers that pull through so they are easier to read. At the moment in the above example D10 results in $-600000000. I'd like it to look like $(600,000,000).

View Replies!   View Related
Conditional Number Format - To Be Used As Number
In Excel 2003, I have a series of complex(ish) lookups which populate cells in Sheet 1 from other sheets in the same workbook. Some of these cells are %ges some are not, I need to display the resultant sheet values as %ges or not based on if the cell to the left (also populated by a complex(ish) lookup) contains the character "%".

I cannot just format the cell on its own, as the list in itself is volatile and can change according to the complex(ish) lookup,

The main problem with this is I need the result to be a numeric value and NOT text in ALL cases as further calculations will be undertaken on them.

In simple if it is a %ge I need to see the %ge and use it as a %ge or if it is just a number see it as a number and use it as a number.


A B Result Req
Satisfaction with telephone access (%) 0.900032390.0%
Ability to see boss within 48 hours () 0.889 0.889

View Replies!   View Related
Format A Number As 1st, 2nd, 3rd Etc.
I cannot figure this out, but does anyone know the custom format code to do a number into 1st, 2nd, 3rd, 4th, 5th, etc.

View Replies!   View Related
Data Validation Format Letter Number Letter Number Etc.
I want to apply Data Validation to a cell, so that only the following combination of letters and numbers can be entered.

Letter Letter Number Number Number Number Number Number Letter.
e.g AB123456C.

View Replies!   View Related
Macro Changes Number Format
From an accounting system I download txt files that then are read into Excel in order to be workable. The numbers come out like this 1.234,00 (ie decimal as comma separator and dot as thousand separator). This does not work in Sweden so I need to get rid of the dot.
I have built a macro that apart from taking out the dot makes some other changes to the data so that one wont have to do the same thing everytime ones downloads the same type of file. The problem is that when creating the macro or just doing the text to column, number format, replacing . with nothing it all works well but when I run the macro some of the numbers become text, others are ok and for some of them the macro does not only take out the dot but also the comma (which makes a huge difference). I have both Excel 2003 and 2007 and the same thing happens with both.....

View Replies!   View Related
Changing Number Format
Please take a look at the attached spreadsheet. in the ODDS column D, after download the some of the data has been changed from say 100-1 to a series of numbers how do i change them back i would also like to show the odds is they were 100-1 as just 100 and say if the odds were 13/2 then i want to show 7.5 basically i want th first number divided by the second.

View Replies!   View Related
Copy Value & Number Format
Sheets("Sheet2").Range("H1") = TextBox3.Value

it works but the code needs to copy special value&number format not just copy

even better can the text box itself be formated to 00"/"00"/"0000

View Replies!   View Related
Number And Date Format
In Excel is there are way to format a cell automatically dependent on the value in another cell? Specifically, if the user selects "410" from a list in cell O9 and enters numeric characters into cell K6 the format of cell K6 is a whole number. However, if the user selects any other number from the list in cell O9 and enters numeric characters into cell K6 the format of cell K6 is now in dollars. I tried using custom in Excel, which I really would like have it in, with no sucess. I am now thinking the only way to accomplish this task is by VBA code. I am ok with formulas; VBA is a different story.

View Replies!   View Related
Number Format For Inventory
I'm using excel as an inventory database but need to know how to change the number format according to what the user is keeping track of. For example drums, bags , cylinders ect...

How can i change the number format to display the unit of measurement added by user?

View Replies!   View Related
Custom Number Format ...
This workbook has 23 sheets for which this format will apply.

Under 1 man-hour .###
Over 1 man-hour #.##
Over 10 man-hour ##.#
Over 100 man-hour ###
Over 1000 man-hour #,###

View Replies!   View Related
Format Into Text/ Number Value
I have a data set which is in a date format of MM/DD/YY. I have converted it to YYYYMMDD. I now need to copy and permanently past the values so that the value within the cell always reads to result of the date in the format of YYYYMMDD.

-current = 07/01/08
-new format = 20080701 (cell still reads 07/01/08)
-would like the cell to read 20080701

My main goal is to bring this into Access and use this dataset with another data set, which uses the YYYYMMDD format.

View Replies!   View Related
Number Format Switch
I have several phone numbers that I copy and paste from the web:

(888) 456-7890
(333) 234-5678

I need to switch all of them to just standard numbers: They should look like this:


I go to "format" - "cells" - "numbers" but nothing works. I wonder if any formula can do it. It should work for ALL THE LIST, I want something else than change them one by one by hand.

View Replies!   View Related
Custom Number Format..?
If I have the following info:

A1 = 5
A2 = -4
A3 = 0

How can I use Format Cells > Custom to have them display as:

A1 = 5 up
A2 = 4 dn
A3 = Level

I've been trying and trying but keep getting a message that I should use one of Excel's pre-defined formats.

View Replies!   View Related
IF Function For A Number Format
I need a formulat that will ensure that a cell has 12 numeric characters,a dash, and then 3 more numeric characters. I thought this was a simple formula but I cannot get anything to work.


View Replies!   View Related
Number Format In Comment
I am tring to writh the value of the cell formated as "#,##0.000" inside the comment box in this format,...............but ...........could not make it

here is my try

Sub Test()
Dim cf As Double, c As Range

'* Add Comment:
For Each c In Selection
If c <> 0 And IsNumeric(c) Then
cf = Format(c, "#,##0.000")
With c

View Replies!   View Related
Textbox Number Format
what the format would be for 3 numbers in a userform textbox. No decimals, no symbals, just the 3 numbers.

View Replies!   View Related
Format: Number And Reverse
I have a userform into which a user can enter a number. When they exit the TextBox the number that they entered must be formatted into the number format. eg 12345,67 -> 12.345,67 and -12345,67 -> (12.345,67). To do this is not the problem: formatnumber does the trick. What I am struggling with is to get VB to still recognise this as a number. I need the code that does the opposite of formatnumber. (12.345,67) -> -12345,67. I excell it works perfectly when you format a cell as custom: _(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_). I want to be able to do the exact same thing in VB.

View Replies!   View Related
Indian Number Format
for the number inserted in A1 if I pressed comma button it give me 1,000,000 as in the regional setting group of 3 in given. My question is when I press comma button for the inserted value i.e. 1000000 it should give me 10,00,000. First group is of 3 digit and after that all gourps are of 2 digit

Value Excel Gives Result I required this kind of formatting

1000000 1,000,000 10,00,000

2023154568 2,023,154,568 2,02,31,54,568

Pl reply on (email address deleted by moderator)

View Replies!   View Related
Format A Cell That Causes Sum Calculation To Go Over A Pre-set Number
I'm working with Loan amounts and i need to know how to set a excel spread sheet to conditionally format a cell that causes a sum formula to exceed a preset limit.

Example ...

View Replies!   View Related
Custom Phone Number Format
I am looking for a custom number format for phone numbers that will allow extensions to be typed in. I am trued using the standard phone format [

View Replies!   View Related
Conditional Format For Formula Or Number
I have a spreadsheet where I have certain cells that contain a link to copy a number from another tab in the spreadsheet.

At times, I have to plug in a number to try certain values. In doing this, I overwrite the link or formula. I then do an 'undo' to bring it back to the original link or formula.

I would like to put a conditional format based on the cell's content. If it is the formula, leave it as is. If it is overwritten by a number, I want it to change colors to remind me to undo my change when I am done.

The conditional formatting options I have found so far allow me to format according the the value in the cell but not the nature of it's content: number of formula.

View Replies!   View Related
Convert Number To Percent Format
I have built a spreadsheet that pulls data into B60:AA240 (Sheet name is "Actual Numbers Report") from a different sheet in the same workbook. Some of the data is in Number format and the other is in Percent Format. What I would like to do is if AL10 in the Actual Numbers Report sheet says "Actual Numbers" then I would like the cells in B60:AA240 convert to a number format "000,000,000" If AL10 says "Trends" then I want it to convert the cells in B60:AA240 to a percent format "0.0%". I tried creating some code, but it doesn't seem to work.

Private Sub Convert_Percent()
If Not Intersect(Target, Range("B60:AA240")) Is Nothing Then
If .Range("AL9") = "Actual Numbers" Then
Selection.NumberFormat = "000,000,000"
ElseIf .Range("AL9") = "Trends" Then
Selection.NumberFormat = "0.0%"
End If
End If

End Sub

If this can work then the 2nd question I would have is can this same line of thinking work to format the chart that this data is pulled from? So if it is Actual Numbers the chart would be in a number format and if it is Trends then it will change to a percent format?

View Replies!   View Related
Unable To Format Number Within Cell
Working on matching 2 column of numbers.

Unable to match as 1 column has format where number has a space in front of first character.

_425638 as opposed to

Not an underscore tough

Have tried text to columns - have tried editing cell and replacing space with nothing via edit/replace but no joy only way appears to be entering cell and deleting manually - there are thousands to update.

View Replies!   View Related
Warcraft 'gold' Number Format, Or G00.00.00
I am trying to build some spreadsheets that handle exported data from the 'auction house' of the well known warcraft game.

I have exported data, but currency is exported in a concatinated string such as 463200.

In that example there would be 46 gold, 32 Silver and 00 copper. If the string was 63200 there would be 6 Gold, 32 Silver and 00 copper.

As I have about 18 different columns containing currency data I am trying to get excel to handle this format, however I cant seem to find a number format that will work with what is essentially two seperators in the number. Not only do I wish to display gold silver and copper in different colours, I wish to be able to perform calculations on the values.

Thus 463226 + 378475 should equal 841701.

View Replies!   View Related
Conditional Format Number Between The Ranges
I have got following numbers data and I want any number between the ranges repeat again or dupliacated it would highlighted as mentioned

ABC1Start RangeEnd RangeQty221002199100323002349504250025252652710271910621102299190729092929218234823492

As you can see yellow highlighted Ranges between the ranges are repeated again or duplicated that is why they are highlighted

View Replies!   View Related
How To Convert TEXT Into NUMBER Format
I just copied a range of data from a website however these numbers are in TEXT format.

Basically each number in this data set has a SPACE behind. This turn the number into a text itself and i cannot do a sum for this range of data. I tried TRIM function and also tried to format it to number but no luck. Also tried to mutilply the range to 1 yet they're still in text format.

View Replies!   View Related
Variable Number Format Before Value Entered
I am entering values in columns AV and BD of the attached spreadsheet. Rather than manually editing each value to adopt the decimal place value of the adjacent cell is there a formula that can achieve this before the value is entered? The decimal place values are determined using a VLOOKUP table (column3) on the NES tab.

View Replies!   View Related
Number Format (4 Decimals Places) In VBA
I am having an issue with number format in my VBA code. The entire column of column D is format as ###.0000 (4 decimals places). There are certains cells which require zero decimal places. I am using the following bit of code, but it is not working correctly. It is still formatting the cell as 4 decimal places.

View Replies!   View Related
Userform Text Box Number Format
The problem is even though the worksheet cell is formated to 3 places the text box in the Userform shows many more than this. I have used the Control Source set to read the cell value.

The answer I've seen 'txtValue = Format(Value, "000.00")' which seems very neat and tidy but I'm not sure how to use it or where to place it.

View Replies!   View Related
Keep Number Format When Converting To Text
I have an excel file that is used to create a large text file. This is all done manually so I wrote some code to create the file automatically. I have everything working except that I am losing some info. The info is zeros after the decimal point. Almost all of the cells are formatted as numbers with 3 decimal places. It is common to have values of 0.000 that end up just 0 when they are written to the text file. Is there a way to keep the formatting (all decimal places)? Here is an example of code that I am using to write data directly from a cell to the file.

View Replies!   View Related
Number Format And Duplicates Check
I am trying to improve my expense report template and need to check on the load if expense report number has been loaded correctly as well as if this report has been previously loaded. Expense report number format looks like this: AAA-BBBBBB-CC

AAA Employee ID #
BBBBBB End of the week date

CC Weekly expense report number
For instance, 023-122008-01 means: Employee number 023, week ending date 12/20/2008, weekly expense report number 01. I would like to prevent/give warning of loading incorrect expense report number format, check for possible duplicates, and check if trying to load expense report belongs to the right person (by simply matching previously loaded in different cell of the same sheet employee ID and first three digits of just loaded expense report number. I think I know how to do all of these separate, but have no idea how to combine all three checks for one cell.

View Replies!   View Related
Cannot Change Cells Number Format
I cannot change the number format in a single sheet of my spreadsheet. I can go to format cells and select colour etc but it will not change the number format.

Another issue on the same sheet is that linked cells i.e cell b3 formula "=A3" displays "=A3" not the actual value in A3. Again, i cannot change the number format of this cell and yes, auto calc is on.

Whilst not wanting to offer a partial explaination (per the rules) just before this happened i was pressing a combitation of Shift+Control+` - not sure if that is relevant.

I want to get the sheet back to its 'normal' working order.

View Replies!   View Related
Number Custom Format A Cell
is it possible to custom format a cell in order to:

a) Present 3.33333 as 3.33 (max. of 2 decimal digits or less)
b) Present 3.333 as 3.33
c) Present 3.33 as 3.33
d) Present 3.3 as 3.3
e) Present 3 as 3 (NO zeros and NO decimal dot)

View Replies!   View Related
Conditional Custom Number Format
I am trying to create a number format for formatting resistor value in their most commonly displayed form. For example 1,200 ohms would be displayed as 1.2k and 5,000,000 ohms would be displayed as 5M, and finally 5 ohms would be displayed as 5. I have been able to create a format that formats any 2 contiguous formats but not all three.

for example: [>999999]###.0,,;[<1000000]###.0,k;
or: [>999]###.0,k;[<1000]###

both work.(other similar criteria work as well) But if I try to put 3 conditions describing the desired formatting I get and error (containing no useful info) as I try to close the formatting dialog. Is there a limit to the number of conditions that can be used. Or something else I'm overlooking.

View Replies!   View Related
Format Number & Text In Same Cell
i have the next formula

=IF(C6="PRODUCT 1","$"&VLOOKUP(B6,N:T,3,FALSE)&" & "&"$"&VLOOKUP(B6,N:T,5,FALSE),"N/A)

which aberrantly returns text:

$24.675 & $26.2

I was wandering is there a way to format or put a formula which will format the numbers to be with two decimal places. The cell containing the formula is already formatted as number and the source tables are numbers with two decimal places.

i want the result to look like this
$24.68 & $26.20

View Replies!   View Related
Format For License Plate Number
I want to format a cell so it changes from


Input "xy32456"

Output "XY 32 456"

Its a license plate register and I would like it automatically to make spaces between the 2 first letters and again after the following 2 numbers. The code I found searching google was

"LL 00 000"

but that doesnt change anything.

I am not sure if its possible but if anybody has an idea of how to solve it, I would apreciate it mostly.

View Replies!   View Related
Custom Number Format Multiply
Is there any way to get a custom number format to display a multiple of the cell value? e.g. can I have a cell have the value 0.005 and display the value 50?

View Replies!   View Related
Format Cell Number Based On Value
I need to evaluate some offers and for the management I need to follow some strict rules like:

1. 1.000.000 instead of 1000000. But that's not the problem
2. to use maximum 3 digits... Example: 10,2 or 6.12

I tried with an if function and then round, but I think that's not right way. If number < 10, then round with 2 decimal places else, round with 1 decimal place

View Replies!   View Related
Copyright 2005-08, All rights reserved