ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   format cells as "Text" (https://www.excelbanter.com/excel-programming/366792-format-cells-text.html)

Phaedrus

format cells as "Text"
 

Hi,

I'm copying a some numerical -codes into a range (say "A:B"), some of
the codes starts with a zero so, after copy Excel converts them numbers
and removes the leading zero.
This is creating a slight problem in my program.

If anybody knows a way to format the range as Text or String, using VBA
in a macro, please let me know.

I cannot do the excel formatting and save the sheet coz' the sheet is
created based on certain user-input.

Thanks in Advance,
Maneesh Hari


Die_Another_Day

format cells as "Text"
 
Range("A:B").NumberFormat= "@"

HTH

Die_Another_Day

Phaedrus wrote:
Hi,

I'm copying a some numerical -codes into a range (say "A:B"), some of
the codes starts with a zero so, after copy Excel converts them numbers
and removes the leading zero.
This is creating a slight problem in my program.

If anybody knows a way to format the range as Text or String, using VBA
in a macro, please let me know.

I cannot do the excel formatting and save the sheet coz' the sheet is
created based on certain user-input.

Thanks in Advance,
Maneesh Hari



Phaedrus

format cells as "Text"
 

DAD :),

this option works perfect. (I was trying with = "Text" and it was
giving me garbage data)

thanks for your help. Really appreciate it.
Maneesh

Die_Another_Day wrote:
Range("A:B").NumberFormat= "@"

HTH

Die_Another_Day

Phaedrus wrote:
Hi,

I'm copying a some numerical -codes into a range (say "A:B"), some of
the codes starts with a zero so, after copy Excel converts them numbers
and removes the leading zero.
This is creating a slight problem in my program.

If anybody knows a way to format the range as Text or String, using VBA
in a macro, please let me know.

I cannot do the excel formatting and save the sheet coz' the sheet is
created based on certain user-input.

Thanks in Advance,
Maneesh Hari



Die_Another_Day

format cells as "Text"
 
Maneesh, An easy way to figure out formatting is to change it manually in
Excel, select the cell then type ?ActiveCell.NumberFormat in the immediate
window in the VBA editor. Glad to be of help to you.

Die_Another_Day

"Phaedrus" wrote in message
oups.com...

DAD :),

this option works perfect. (I was trying with = "Text" and it was
giving me garbage data)

thanks for your help. Really appreciate it.
Maneesh

Die_Another_Day wrote:
Range("A:B").NumberFormat= "@"

HTH

Die_Another_Day

Phaedrus wrote:
Hi,

I'm copying a some numerical -codes into a range (say "A:B"), some of
the codes starts with a zero so, after copy Excel converts them numbers
and removes the leading zero.
This is creating a slight problem in my program.

If anybody knows a way to format the range as Text or String, using VBA
in a macro, please let me know.

I cannot do the excel formatting and save the sheet coz' the sheet is
created based on certain user-input.

Thanks in Advance,
Maneesh Hari






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

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