View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default formatting a variable problem

First, using "As Date" will keep the value a date--not text (Format() returns
text).

So either use two variables or use "As Variant"

Second, when working with dates, it's probably better to use the .value2
property.

Spike wrote:

I nave a problem formatting a variable. If i run the following in a sub it
has no effect on the variable value, howeverif i pass the variable to another
sub and run the same formatting code on it it does it as i want.

Dim datCFwd As Date

datCFwd = Sheets("Model").Range("Model_AccountingEnd").Value
datCFwd = Format(datCFwd, "dd mmm yy")

the range Sheets("Model").Range("Model_AccountingEnd") is custom formatted
as "dd-mmm-yy" but the variable actuallly holds the value as "dd/mm/yy" and
this does not change unless it is passed to another sub as explained above

Any ideas to correct this will be very gratefully received.

--
with kind regards

Spike


--

Dave Peterson