Pass date to cell as string

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Pass date to cell as string

Post by Rudi »

Hi,

How can I pass a variable holding a string date (YYYY-MM) to a cell without it calculating as 2012 minus 10 resulting in 2002
See screenshot

Any ideas...TX :)
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Pass date to cell as string

Post by HansV »

Place quotes around the string value:

Code: Select all

... = "=INDIRECT(""B""&ROW())&"" ""&INDIRECT(""D""&ROW())&"" ""&""" & ShName & """"
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Pass date to cell as string

Post by Rudi »

TX....it worked!!

I tried that but I must have got the quote count wrong??!!
Even tried:
- CStr(ShName)
- Str(ShName)
- Format(ShName,"@")
....
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Pass date to cell as string

Post by HansV »

It doesn't matter whether you use CStr or Str or Format - without those quotes, the formula will end in

...&2012-10

which causes Excel to evaluate 2012-10 to 2002. Adding the quotes changes the formula to

...&"2012-10"

which appends the string "2012-10".
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Pass date to cell as string

Post by Rudi »

Cheers...TX for the help!
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.