ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Replace leading zeros with leading spaces ? (https://www.excelbanter.com/excel-programming/438068-replace-leading-zeros-leading-spaces.html)

Gary

Replace leading zeros with leading spaces ?
 
I am using Excel 2007.
Format (12,000) gives me 012
I want (12,??0) to be 12 with a leading space

Question mark doesnt seem to work in Excel 2007


Rick Rothstein

Replace leading zeros with leading spaces ?
 
Use this...

Format(12, "@@@")

--
Rick (MVP - Excel)


"Gary" wrote in message
...
I am using Excel 2007.
Format (12,000) gives me 012
I want (12,??0) to be 12 with a leading space

Question mark doesnt seem to work in Excel 2007



Gary

Replace leading zeros with leading spaces ?
 
I need Format because this is part of a loop building a dynamic Message Box
that has several columns; I need the columns to be aligned for readability.

Gary

"Ryan H" wrote:

I don't think you need to use Format.

So you want "12" to look like " 12"?

MyString = " 12"

But I know if can't be that simple. Is "12" a value in a cell? If so, use
this:

MyString = " " & Range("A1").Value
--
Cheers,
Ryan


"Gary" wrote:

I am using Excel 2007.
Format (12,000) gives me 012
I want (12,??0) to be 12 with a leading space

Question mark doesnt seem to work in Excel 2007


Gary

Replace leading zeros with leading spaces ?
 
YES !!! That works .

Thanks,

Gary

"Rick Rothstein" wrote:

Use this...

Format(12, "@@@")

--
Rick (MVP - Excel)


"Gary" wrote in message
...
I am using Excel 2007.
Format (12,000) gives me 012
I want (12,??0) to be 12 with a leading space

Question mark doesnt seem to work in Excel 2007


.


Ryan H

Replace leading zeros with leading spaces ?
 
You can also use

Val(your string here)

For example,

Val(0000012) = 12
--
Cheers,
Ryan


"Gary" wrote:

I need Format because this is part of a loop building a dynamic Message Box
that has several columns; I need the columns to be aligned for readability.

Gary

"Ryan H" wrote:

I don't think you need to use Format.

So you want "12" to look like " 12"?

MyString = " 12"

But I know if can't be that simple. Is "12" a value in a cell? If so, use
this:

MyString = " " & Range("A1").Value
--
Cheers,
Ryan


"Gary" wrote:

I am using Excel 2007.
Format (12,000) gives me 012
I want (12,??0) to be 12 with a leading space

Question mark doesnt seem to work in Excel 2007



All times are GMT +1. The time now is 10:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com