Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Storing string in names

Hi,
I stored some invisible data in the workbook by using the names. It
works perfectly in most case. But when I assigned a string that only
contains numeric chars to a name. It comes out with an integer and the chars
has been changed! (Just like when u type "0001" into a cell in excel it
auto-format and change it to "1")
Anyone knows how to prevent the auto-format happened in the content of
names? Thx.
Here is the quote of my code:

Dim key as string
key = "0000304"
ThisWorkbook.Names.Add Name:="key", RefersTo:=key, Visible:=False
MsgBox [key]
'I want "0000304" but it gave "304"


Thanks a lot

Michael


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Storing string in names

Hi,

All you can do is add a letter to the string, e.g.:

Dim key As String
key = "00001"
ThisWorkbook.Names.Add "key", "A" & key, False
MsgBox ThisWorkbook.Names("key")

But the name will then contain this:

="A00001"

So you will need to strip away the unneeded junk to get
your numbercode back.

Why are you storing things in names?
You could also use variables declared outside procedures
(at the top of a module).

Regards,

Jan Karel Pieterse
Excel TA/MVP

-----Original Message-----
Hi,
I stored some invisible data in the workbook by using

the names. It
works perfectly in most case. But when I assigned a

string that only
contains numeric chars to a name. It comes out with an

integer and the chars
has been changed! (Just like when u type "0001" into a

cell in excel it
auto-format and change it to "1")
Anyone knows how to prevent the auto-format happened

in the content of
names? Thx.
Here is the quote of my code:

Dim key as string
key = "0000304"
ThisWorkbook.Names.Add Name:="key", RefersTo:=key,

Visible:=False
MsgBox [key]
'I want "0000304" but it gave "304"


Thanks a lot

Michael


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Storing string in names

Hi Michael. Use ' in front of the number - Excel handles it as a string.
Like: "'0000304"

Regards, Alfred

"Michael Tse" wrote in message
...
Hi,
I stored some invisible data in the workbook by using the names. It
works perfectly in most case. But when I assigned a string that only
contains numeric chars to a name. It comes out with an integer and the

chars
has been changed! (Just like when u type "0001" into a cell in excel it
auto-format and change it to "1")
Anyone knows how to prevent the auto-format happened in the content of
names? Thx.
Here is the quote of my code:

Dim key as string
key = "0000304"
ThisWorkbook.Names.Add Name:="key", RefersTo:=key, Visible:=False
MsgBox [key]
'I want "0000304" but it gave "304"


Thanks a lot

Michael




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Storing string in names

Michael,

You could do it this way, which specifies that your value is a string:

key = "=""0000304"""


--

John Green - Excel MVP
Sydney
Australia


"Michael Tse" wrote in message ...
Hi,
I stored some invisible data in the workbook by using the names. It
works perfectly in most case. But when I assigned a string that only
contains numeric chars to a name. It comes out with an integer and the chars
has been changed! (Just like when u type "0001" into a cell in excel it
auto-format and change it to "1")
Anyone knows how to prevent the auto-format happened in the content of
names? Thx.
Here is the quote of my code:

Dim key as string
key = "0000304"
ThisWorkbook.Names.Add Name:="key", RefersTo:=key, Visible:=False
MsgBox [key]
'I want "0000304" but it gave "304"


Thanks a lot

Michael




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Storing string in names

Thanks for the idea. This is a pratical approach and I will take it if there
is no other better approach. (Since I still hope the string can be read and
written directly)

I use names instead of variables since the data need to be persist in the
workbook after it
is saved. U know, variables will be lost after the workbook is closed.

Michael

"Jan Karel Pieterse" ???
???...
Hi,

All you can do is add a letter to the string, e.g.:

Dim key As String
key = "00001"
ThisWorkbook.Names.Add "key", "A" & key, False
MsgBox ThisWorkbook.Names("key")

But the name will then contain this:

="A00001"

So you will need to strip away the unneeded junk to get
your numbercode back.

Why are you storing things in names?
You could also use variables declared outside procedures
(at the top of a module).

Regards,

Jan Karel Pieterse
Excel TA/MVP

-----Original Message-----
Hi,
I stored some invisible data in the workbook by using

the names. It
works perfectly in most case. But when I assigned a

string that only
contains numeric chars to a name. It comes out with an

integer and the chars
has been changed! (Just like when u type "0001" into a

cell in excel it
auto-format and change it to "1")
Anyone knows how to prevent the auto-format happened

in the content of
names? Thx.
Here is the quote of my code:

Dim key as string
key = "0000304"
ThisWorkbook.Names.Add Name:="key", RefersTo:=key,

Visible:=False
MsgBox [key]
'I want "0000304" but it gave "304"


Thanks a lot

Michael


.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Storing string in names

Thx Alfred.
I set added single quote in front of the number but it returned the
string with the quote as well when I retrieve the data from the name.
Cheers,
Michael

"Alfred B" ¦b¶l¥ó
¤¤¼¶¼g...
Hi Michael. Use ' in front of the number - Excel handles it as a string.
Like: "'0000304"

Regards, Alfred

"Michael Tse" wrote in message
...
Hi,
I stored some invisible data in the workbook by using the names. It
works perfectly in most case. But when I assigned a string that only
contains numeric chars to a name. It comes out with an integer and the

chars
has been changed! (Just like when u type "0001" into a cell in excel it
auto-format and change it to "1")
Anyone knows how to prevent the auto-format happened in the content

of
names? Thx.
Here is the quote of my code:

Dim key as string
key = "0000304"
ThisWorkbook.Names.Add Name:="key", RefersTo:=key, Visible:=False
MsgBox [key]
'I want "0000304" but it gave "304"


Thanks a lot

Michael






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Storing string in names

John,

It solved the problem perfectly, thx a lot.

Cheers,
Michael
"John Green" ¦b¶l¥ó
¤¤¼¶¼g...
Michael,

You could do it this way, which specifies that your value is a string:

key = "=""0000304"""


--

John Green - Excel MVP
Sydney
Australia


"Michael Tse" wrote in message

...
Hi,
I stored some invisible data in the workbook by using the names. It
works perfectly in most case. But when I assigned a string that only
contains numeric chars to a name. It comes out with an integer and the

chars
has been changed! (Just like when u type "0001" into a cell in excel it
auto-format and change it to "1")
Anyone knows how to prevent the auto-format happened in the content

of
names? Thx.
Here is the quote of my code:

Dim key as string
key = "0000304"
ThisWorkbook.Names.Add Name:="key", RefersTo:=key, Visible:=False
MsgBox [key]
'I want "0000304" but it gave "304"


Thanks a lot

Michael






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract names from string based on value list Pluggie Excel Worksheet Functions 2 December 3rd 09 05:35 PM
storing data JK57 Excel Worksheet Functions 3 May 1st 06 12:16 AM
Storing Formulas to Use NEWB Excel Worksheet Functions 3 December 2nd 05 05:23 PM
Storing data Bob Mckenzie New Users to Excel 3 July 30th 05 07:33 PM
Storing Values dinesh Excel Discussion (Misc queries) 0 June 10th 05 06:33 AM


All times are GMT +1. The time now is 08:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"